Simple User-Input AKA a DOS application.

I've been doing some programming using the simple DOS commands, and reading keyboard input to read strings into variables.
I've got an Applet at the moment with a text area (several rows high), and a text field (single line), and I've got the text area reading a string variable into it, and the text field appending it's value to the variable on the event that you hit enter..
But the issue I'm having is that, unlike the DOS commands, I can't get the processing to stop and wait for an input, then continue...
If anyone could help out, it would be great, Thanks!

Here's my code at the moment... the commented out lines in the input class are wherre im playing around at the moment...
Any help or references appreciated.
Thanks :)
// File: Console.java
package MyConsoleIO;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Console extends JApplet
                    implements ActionListener{
    private JTextField      inputBox;
    private JTextArea      textBox;
    private String           gotString = "";
    private Game           game;
    public void trace(String msg){System.out.println(msg);}
    public void println(String msg){
         textBox.append("\n"+msg);
         trace("Tried to print: "+msg);
    public void init() {
         game = new Game();
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    createGUI();
        } catch (Exception e) {
            System.err.println("createGUI didn't successfully complete");
    private void createGUI() {
        JPanel contentPane = new JPanel(new GridBagLayout());
        contentPane.setBorder(BorderFactory.createCompoundBorder(
                                    BorderFactory.createLineBorder(Color.BLACK),
                                    BorderFactory.createEmptyBorder(10,10,5,5)));
        setContentPane(contentPane);
        GridBagConstraints c = new GridBagConstraints();
        c.insets = new Insets(0,0,5,5);
//        // Label
//        JLabel receiverLabel = new JLabel(">",
//                                          JLabel.TRAILING);
//        add(receiverLabel, c);
        // Text Field
        inputBox = new JTextField("Type Something", 10);
        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 1.0;
        add(inputBox, c);
        inputBox.addActionListener(this);
        // Button
        JButton button = new JButton(">");
        c.gridwidth = GridBagConstraints.REMAINDER; //end row
        c.anchor = GridBagConstraints.LINE_START; //stick to the
                                                  //text field
        c.fill = GridBagConstraints.NONE; //keep the button
                                          //small
        c.weightx = 0.0;
        add(button, c);
        button.addActionListener(this);
        // Text Box
        textBox = new JTextArea(30, 80);
        textBox.setEditable(false);
        c.anchor = GridBagConstraints.CENTER; //reset to the default
        c.fill = GridBagConstraints.BOTH; //make this big
        c.weighty = 1.0;
        add(new JScrollPane(textBox), c);
    public void actionPerformed(ActionEvent event) {
         textBox.append("\n"+inputBox.getText());
         gotString = inputBox.getText();
         inputBox.setText("");
         Input.inString = gotString;
    public void start(){
         textBox.append(Output.messagelist);
// File: Game.java
package MyConsoleIO;
public class Game{
     public Game(){
          Output.println("Game Started!");
          String name = Input.getString("Please enter your name: ");
          Output.println(name + ", ay... how odd.");
          Output.println("GAME OVER");
// File: Input.java
package MyConsoleIO;
public class Input{
     static public String inString = "";
     public static String getString(String message){
          Output.println(message);
//          while(inString.length() == 0){
//               // wait for some input...
          return inString;
// File: Output.java
package MyConsoleIO;
public class Output {
     public static String messagelist = "";
     public static void println(String line){
          messagelist += "\n" + line;
}

Similar Messages

  • Can I capture crystal report user input in my web application?

    Folks, I have a report that has a input paramter named "AccountKey". Crystal report launches its own input parameter capture screen where user can type in the AccountKey value and hit OK button. Subsequently the crystal report gets renedred in crystal report viewer.
    I have a requirement of rendering the report in PDF not in crystal report. How do I do that.
    I am able to do that when there is no user input needed in the crystal report or, if I can somehow supply needed input from code-behind, but the moment I has a parameter that expects user-input I loose control.
    Is there anyway I can capture what value user has entered in Crystal Report Input paramagter capture form? or, any alternate that can help me acheive the result?
    Thanks.

    Hi,
    To capture the values of Parameters the best thing you can do is to code for parameters and take values from it through text boxes, so that you can capture it.
    here some sample code for it - try it
    I would like you to know the following code that I have tried at my end using Viewer Object model:
    // Object Declaration
    ParameterFields boParameterFields = null;
    ParameterField boParameterField = null;
    ParameterValues boParameterValues = null;
    ParameterDiscreteValue boParameterDiscreteValue = null;
    ParameterRangeValue boParameterRangeValue = null;
    // loading the report
    CrystalReportViewer1.ReportSource = Server.MapPath("ReportWithSubReport.rpt");
    CrystalReportViewer1.RefreshReport();
    // passing database credentials...
    foreach(CrystalDecisions.Shared.TableLogOnInfo boTableLogOnInfo in CrystalReportViewer1.LogOnInfo)
                  ConnectionInfo boConnectionInfo = boTableLogOnInfo.ConnectionInfo;
                  boConnectionInfo.UserID ="sa";
                  boConnectionInfo.Password="sa";
    // Parameter Country
    boParameterFields = CrystalReportViewer1.ParameterFieldInfo;
    boParameterField = boParameterFields["Country"];
    boParameterValues = boParameterField.CurrentValues;
    boParameterDiscreteValue = new ParameterDiscreteValue();
    boParameterDiscreteValue.Value = "Argentina";
    boParameterValues.Add(boParameterDiscreteValue);
    // Parameter Sales
    boParameterField = boParameterFields["Sales"];
    boParameterValues = boParameterField.CurrentValues;
    boParameterRangeValue = new ParameterRangeValue();
    boParameterRangeValue.StartValue = 25000;
    boParameterRangeValue.EndValue = 100000;
    boParameterValues.Add(boParameterRangeValue);
    // Parameter @percentage in subreport named SubReport
    boParameterField = boParameterFields["@percentage", "SubReport"];
    boParameterValues = boParameterField.CurrentValues;
    boParameterValues.Clear();
    boParameterDiscreteValue = new ParameterDiscreteValue();
    boParameterDiscreteValue.Value = 75;
    boParameterValues.Add(boParameterDiscreteValue);
    Please note that I have used Range and Discrete values as parameter in the above code.
    Also if you want to use the ReportDocument Object model then you can use:
    ReportDocument.SetParameterValues("Parameter name", value)
    Note:- This code is valid for only discrete values of Parameters.
    or
    boParameterFieldDefinitions = boReportDocument.DataDefinition.ParameterFields;
    boParameterFieldDefinition = boParameterFieldDefinitions["@percentage","SubReport"];
    boParameterValues = boParameterFieldDefinition.CurrentValues;
    For getting output in PDF you can export the report to PDF throug viewer or from code fro e.g.-
    boReportDocument.ExportToDisk(ExportFormatType.portabledocumentformat,"c:\\temp\\myrpt.pdf");
    To download sample code click [here|https://boc.sdn.sap.com/codesamples].
    You can also take help from [Dev library|https://boc.sdn.sap.com/node/7770]
    Hope this helps!!
    Regards,
    Amit

  • User Input in Dos Programs

    Hi, sorry for such as newbie type question but iv just started programming in Java (so im used to the simpleness of vb). I have a simple Java Dos program, and i understand the system. functions but was wondering how i could get the > user input prompt. any help would be greatly appreciated. thanks!
    WC

    See if this isn't what you want:
    import java.io.*;
    // This program displays the user's input
    public class GetInput {
         public static void main(String[] args) throws IOException {
              // This is how we set things up to read lines of text from the user.
              BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
              // Loop forever
              for(;;) {
                   // Display a prompt to the user
                   System.out.print("Type something> ");
                   // Read a line from the user
                   String line = in.readLine();
                   // If the input is null or if the user types �quit�, then quit
                   if (line.equals("") || line.equals("quit"))
                         break;
                   try {
                        System.out.println(line);
                   // If anything goes wrong, display a generic error message
                   catch(Exception e) {
                        System.out.println("Invalid Input");
    }

  • Open CC applications to default preferences with no user input

    I am searching for a way to open CC applications to default preferences with no user input. I understand there is a key board short cut (command/option/shift on start) but I am hunting for a way to have the preferences always revert to default. In the past I have written a script to delete the preference files upon computer start up but once again, it needs to be rewritten. Is there a method that does not require KLUDGE?

    Try:
    *http://kb.mozillazine.org/Preferences_not_saved

  • Need User input pop-up in powershell when its run as a background process of an Application

    Hi,
    I have created a powershell script which requires two parameters to be passed onto it for getting executed. This script is called by an application and runs it in background (no console /  window). During this process the application is unable to complete
    the execution of the script due to the missing user inputs (no popup comes for entering parameters by even after using read-host/[system.console]::Read()). 
    The powershell.exe process can only be seen in task manager.
    Is there a way in which my script will create a pop up and ask for the parameter values?
    Thanks,
    Sushruta Banerjee

    Hi,
    I have created a powershell script which requires two parameters to be passed onto it for getting executed. This script is called by an application and runs it in background (no console /  window). During this process the application is unable to complete
    the execution of the script due to the missing user inputs (no popup comes for entering parameters by even after using read-host/[system.console]::Read()). 
    The powershell.exe process can only be seen in task manager.
    Is there a way in which my script will create a pop up and ask for the parameter values?
    Thanks,
    Sushruta Banerjee
    Note that a process that runs with hidden windows will have all of its child process windows hidden. Any popup you add to the script will behidden.  There is nothing you can do about that.  This is by design.
    ¯\_(ツ)_/¯

  • User inputs and simple anim.

    I know this is a bit basic, but I'm having trouble getting this animation to respond to user inputs. I want the circle to start near the centre of the screen and move up until it hits Y less than 10. Here, I've started the animation thread as a response to the user input, I know this probably isn't the best way to do it.
    import java.applet.Applet;
    import java.awt.Graphics;
    import java.awt.Color;
    import java.awt.*;
    import java.awt.event.*;
    public class basicAnimation extends Applet implements Runnable, KeyListener
    {Thread aThread;
            public int Y;
         public void start()
              if (aThread == null)
              {aThread = new Thread(this);
                   aThread.start();}
         public void stop()
              if (aThread != null)
              {aThread = null;}
         public void run()
              while (true)
                   for(Y=350; Y<10; Y--)
                   {repaint();
                        try { Thread.sleep(100); }
                        catch (InterruptedException e) { }}
         public void init()
         {Y=350;}
         public void paint(Graphics g)
         {g.fillOval (415, Y, 10, 10);}
       public void keyPressed(KeyEvent e)
           int keyCode = e.getKeyCode();
           switch(keyCode)
           {case KeyEvent.VK_SPACE:
                   aThread.start();
                 break;}
       public void keyTyped(KeyEvent e){}
       public void keyReleased(KeyEvent e){}
    }

    Sorry, now that I have gotten a better look at your run() method. You need to replace what you have with the code that I gave you in the previous post. If you run a for loop that is inside the thread, you will change Y from being at the center to Y == 10 in one thread iteration. This is much too fast for what you want to do.
    Don't forget that the thread is executing something like 1000 times every second (depending on how you set it up and the speed of your machine). So if you put a for loop inside the thread you are running the for loop about 1000 times a second when all you meant to do is run through one time.

  • Error in simple user defined function

    Hi all,
    I have seen one simple user defined function on scenario. Now it is working fine. Same code I have used another place. But it is giving some errors
    D:/usr/sap/C08/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapc6fa0c70297511dbaf7e00c09f4504e7/source/com/sap/xi/tf/_ST_MM_.java:3: package javax.mail.internet does not exist
    import com.sap.aii.mappingtool.tf3.;import com.sap.aii.mappingtool.tf3.rt.;import java.util.;import java.io.; import java.lang.reflect.;import javax.mail.internet.;import javax.mail.;import java.util.;import java.util.Date;import javax.activation.;import java.lang.reflect.;import javax.mail.event.*;
    Like that it has shown 13 errors. I have given the package names in imports field what previous function has.

    Hi,
    Please see this from SAP help
    <i>a.      You can import Java packages to your methods from the Imports input field, by specifying them separated by a comma or semi-colon:
    You do not need to import the packages java.lang., java.util., java.io., and java.lang.reflect. since all message mappings require these packages and therefore import them. You should be able to access standard JDK and J2EE packages of the SAP Web Application Server by simply specifying the package under Import. In other words, you do not have to import it as an archive into the Integration Repository. You can also access classes of the SAP XML Toolkit, the SAP Java Connector, and the SAP Logging Service (see also: Runtime Environment (Java-Mappings)).
    In addition to the standard packages, you can also specify Java packages that you have imported as archives and that are located in the same, or in an underlying software component version as the message mapping.
    b.      Create your Java source text in the editor window or copy source text from another editor.</i>
    http://help.sap.com/saphelp_nw04/helpdata/en/22/e127f28b572243b4324879c6bf05a0/content.htm
    Regards
    Vijaya

  • How to pass user input in automator to a variable?

    I want to ceate a workflow/application to
    -create a new folder eg Batch001 in directory B
    -grab a group of folders in directory A
    -and move them to Batch001
    -create an archive of Batch001
    -create a new set of empty folders in directory A
    I thought I had this worked out, and planned to create a small applescript to grab a user input, then pass it to a variable. Figured if I do that at the beginning I can use the variable to create the Batch folder name, which I would enter manually. There will be a number of them, but not hundreds.
    I have an applescript in automator to show a dialog, but ti does not seem to pass anything to the results. Even if I just use a simple dialog no results are passed. If I run it in actionscript editor it shows a result as expected.
    on run {input, parameters}
      --Display Dialog and Get Input
      display dialog "Batch Number?" default answer "BatchXXX"
      --Get Answer & Return Comment
      set input to (text returned of result)
      return input
    end run

    I tried that, but when I run my workflow, it fails and I get an error message: The action “Rename Finder Items” encountered an error.
    Here are a couple of screenshots of my workflow:

  • Producer Consumer & User Events with user input windows

    Hello All,
    I am planning to build Labview code using the Producer Consumer & User events pattern, the application needs multiple user input windows for things like personal data, feature selection etc, there could be around 15 or 20 distincts screen/panels required.
    The main question from me is... Is there a best practive approach to navigating/loading from one window to another etc, and also providing a way to to retrun to the previous window.
    Also I may need need to be running some slow logging and control hardware in the background while navigating some of the screens, this seems like the producer consumer vi will be running in the background while the user input causes a load/display window event.
    A simple Producer Consumer multiple winjdoow example would be very welcome. Thanks.
    Regards Chris

    I will second Mike's suggestion to use a central VI with subpanel(s).  It is usually less confusing than multiple windows.  Typically, the selection/navigation mechanism is on the left of the main panel, global info (like help) on the right, and the subpanel(s) in the center.
    The advantage of subpanels/subVIs is that you can launch your subVIs and keep them active in the background, even though they are not being used.  This means they will keep their state information and load into the subpanel almost instantaneously the next time you need them.  For a short tutorial on subpanels, check out this link.  Scroll down to the fourth reply for working code.  The original code posted is broken.
    Communication between your VIs or loops is typically done with either queues or event structures.  State information in each should be shift registers in the respective VIs.  If you have the time, I would highly recommend you learn how to use LabVIEW classes.  The command pattern is tailor made for this kind of application.
    Finally, avoid global data if you can.  Global data is anything that you can get to from anywhere (globals, functional globals, etc.).  Use of these can speed your development, but can also lead to sloppy design which will cause you major problems later.  If you really need globally available data, use a data value reference.  It is unnamed and requires a reference, which tends to enforce better programming practice.  Yes, there are instances where you truly need globally available, named data, but they are fairly rare.  You should only use them if you are experienced and really know what you are doing.
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • How to calculate elapsed time based on user input

    I'm not sure what to do next in this program. Basically, I'm not sure exactly how to get the time to output accurately, as in what forumla I should be using.
    This is the question:
    What comes 13 hours after 4 o'clock? Create an ElaspedTimeCalculator application that prompts the user for a starting hour, whether it is am or pm, and the number of elapsed hours. The application then displays the time after that many hours have passed. Application output should look similar to:
    Enter the starting hour: 7
    Enter am or pm: pm
    Enter the number of elapsed hours: 10
    The time is: 5:00 amHere's the code I have so far:
    import java.util.Scanner;
    public class ElapsedTimeCalculator
         public static void main(String[] args)
              int starting_hour;
              int starting_minutes; /*This is added in case the user wants to add minutes as well.*/
              String am_or_pm;
              int elapsed_hours;
              int elasped_minutes;
              int time_hours;
              int time_minutes;
              System.out.println("Welcome. This application will give you the time based on your input.");
              System.out.println(" ");
              Scanner input = new Scanner(System.in);
              System.out.print("Enter the starting hour: ");
              starting_hour = input.nextDouble();
              System.out.print("Enter the starting minutes: ");
              starting_minutes = input.nextDouble();
              System.out.print("Enter either 'am' or pm': ");
              am_or_pm = input.nextString();
              System.out.print("Enter the number of elapsed hours: ");
              elapsed_hours = input.nextDouble();
              input.close();
              time_hours =
              time_minutes = 
              if(am_or_pm = "am" || am_or_pm = "a.m." || am_or_pm = "AM" || am_or_pm = "A.M.")
                   System.out.println("The time is " + time_hours + ":" + time_minutes + "am");
              if(am_or_pm = "pm" || am_or_pm = "p.m." || am_or_pm = "PM" || am_or_pm = "P.M.")
                   System.out.println("The time is " + time_hours + ":" + time_minutes + "pm");
    }To calculate time_hours should I just calculate this by adding the elapsed hour to the starting hour? I doubt it will be accurate for all situations.
    Same for the time_minutes For example, if the starting minutes and the elapsed minutes were 50, it would be greater than 60. Also, not sure if it makes sense to separate hours and minutes like this, it's not required to in the question. I initally thought it would be easier to approach like this instead of allowing the user to input a double for the starting hour. ex. 5.7
    I get the feeling that this is extremely simple, but nonetheless, I'm stuck, so any help would be appreciated.

    Well thanks to both of you. I did a little reading up on the modulus operator and coupled it with some logic (although, truthfully, I'm not really using to there actually being an application for the remainder of a division operation, since it's never really used very much in any of my Math courses) and the hours portion works perfectly now:
    import java.util.Scanner;
    public class ElapsedTimeCalculator
         public static void main(String[] args)
              int starting_hour;
              //int starting_minutes; /*This is added in case the user wants to add minutes as well.*/
              String am_or_pm;
              int elapsed_hours;
              //int elasped_minutes;
              System.out.println("Welcome. This application will give you the time based on your input.");
              System.out.println(" ");
              Scanner input = new Scanner(System.in);
              System.out.print("Enter the starting hour: ");
              starting_hour = input.nextInt();
              //System.out.print("Enter the starting minutes: ");
              //starting_minutes = input.nextInt();
              System.out.print("Enter either 'am' or pm': ");
              am_or_pm = input.next();
              System.out.print("Enter the number of elapsed hours: ");
              elapsed_hours = input.nextInt();
              input.close();
              int time_hours = 0;
              //int time_minutes;
              String meridien;
              if(am_or_pm.equals("am"))
                   time_hours = (starting_hour + elapsed_hours) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("am"))
                   time_hours = (starting_hour + elapsed_hours) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("AM"))
                   time_hours = (starting_hour + elapsed_hours) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("A.M."))
                   time_hours = (starting_hour + elapsed_hours) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("pm"))
                   time_hours = (starting_hour + elapsed_hours + 12) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("p.m."))
                   time_hours = (starting_hour + elapsed_hours + 12) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("PM"))
                   time_hours = (starting_hour + elapsed_hours + 12) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("P.M."))
                   time_hours = (starting_hour + elapsed_hours + 12) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              if(time_hours < 12)
                   meridien = "A.M.";
                   System.out.println("The time is: " + time_hours + ":00 " + meridien);
              else if(time_hours > 12)
                   meridien = "P.M.";
                   System.out.println("The time is: " + time_hours + ":00 " + meridien);
    }Now the only thing is the minutes. My teacher did say she wants the user to have the option to input minutes also if he/she desires, so I do need it. However, the only problem is that if say the user inputs a "starting minute" of 14 for example, and 66 minutes elapsing, then (14 + 66) int/ 60 = 1r20 but using the modulus operator would only give me 20. So how will I be able to add any extra hours if it is necessary?

  • How do you keep a VI running while waiting for user input?

    I have a VI that:
    1.  The user enters set points.
    2.  The user starts the VI and the VI sends the set points to an external process via a serial interface.
    3.  The VI  stops running.
    4   The user waits for the external process to complete.
    5.  Repeat sequence. Go to Step 1.
    This works well except for one small problem.  Starting the VI in step 2 causes an external micro controller to reset.  During the reset it will ignore set point commands.  To get around this problem a delay has been added between when the VI opens the serial port and when the VI sends the set points to the external process   Is it possible to keep a VI running continuously in this type of application, thereby eliminating the start up and shut down of the serial interface?
    If yes, how do you keep a VI running while waiting for user input?
    Howard

    The ones for the event structure specifically. I'm posting from my phone. Look at the basic ones for user input. even a simple while loop with a boolean and a case statement would work.

  • Slow response from user input

    Hi.
    I have a very strange problem with some of my clients. Sometimes they experience a huge delay between key pressed on keyboard and actual character printed on monitor. So there is a simple text item involved and when the user starts typing the delay could be two or even three seconds between user input (each character) and actual forms displaying it.
    First I suspected network contention but I am not quite sure if there is any network traffic (client browser -> application server) involved while user is typing text into text item. Next I tried to monitor clients machine processes (like anti virus program) but no luck. I have also tried various JRE versions but again no luck.
    I am using 11.1.2.1 version of forms with Mozilla and JRE 1.6.35 on client side.
    Does anybody have/had similar experience? Any suggestion in helping resolving the issue appreciated.
    Also I am really curious what is happening (is there any network traffic involved) while user is typing text into text item where there is no trigger on that item except when_validate_item.
    Best regards.

    Also I am really curious what is happening (is there any network traffic involved) while user is typing text into text item where there is no trigger on that item except when_validate_item.Unless you have implemented a Java Bean on the item to monitor the keystrokes in the field, no events are trigger by the act of typing characters in a field. The act of typing characters in a field occurs completly on the client - no network traffic at this point. Only when a field event occurs (navigation away from the item) will an event occur that would cause network communication between the client and the appilcation server.
    Sometimes they experience a huge delay between key pressed on keyboard and actual character printed on monitor. I encountered something similar to this with a user once who complained about how slow the application ran on their computer. The slowness was intermitant and there was no apparent pattern. Like you, I looked at JRE and other things. Finally, told the user to call me when the slowness occured so I could come look at the computer while it was occuring. Turns out, the user had at least 30+ applications running at the same time. The workstation was running Windows XP with 2gb Ram. Looking at their system resources, there was no memory available and the pc was memory thrashing really bad. I had the user close all but the absolute necessary programs and our Forms application started responding quickly again. After a little user education - miraculously, the slowness problem went away. :)
    Craig...

  • User input in ALV Grid

    Hello All,
    Is it possible to have a user input in ALV grid. I know there can be editable columns/cells but suppose the application demands an input field to be placed in ALV Grid where the user will enter some value.
    Could someone please suggest if this can be done.
    Regards
    Indrajit

    Here's THE definitive way to do it.
    This little proggy demonstrates the following.
    1) Create a DYNAMIC FCAT for an internal table with USER defined fields (i.e non ddic) and colour some columns in the FCAT.
    2) Create a DYNAMIC TABLE.
    3) Define a subclass of CL_GUI_ALV_GRID so you can access some very useful protected methods and attributes - you can get original and changed table IN ROWS which is a lot easier sometimes than messing around with individual
    cells.
    4) Create extra buttons on the toolbar.
    5) Define EVENT handlers including data change so you can get control when the user enters data. YOU DON'T NEED PAI anymore with event handlers.
    6) Call methods in your subclass of CL_GUI_ALV_GRID (you can also call methods in CL_GUI_ALV_GRID by virtue of Inheritance) from methods in your event handler class.
    7) Display an editable Grid.
    This method will work for almost any conditions you need to use.
    I'm sure this covers all the bases -- please reply if any queries.
    Run the program, click on the EDIT button and enter your data. Press ENTER when done.
    All you need to do is copy this code and create one empty screen (SE51) with a custom container called CCONTAINER1  with the following logic in it.
    PROCESS BEFORE OUTPUT.
    MODULE STATUS_0100.
    PROCESS AFTER INPUT.
    MODULE USER_COMMAND_0100.
    (In the program you don't actually do anything in the PAI as the event handler takes care of this)
    Now here's the program
    PROGRAM zdynfieldcat.
    class zcltest definition  deferred.  "For field symbol reference.
    Simple test of dynamic ITAB with user defined (not ddic) fields
    Build dynamic fcat
    Table structure obtained via new RTTI functionality
    use ALV grid to display and edit.
    Create a blank screen 100 with a custom container called CCONTAINER1.
    Define field symbols as these can't be defined in classes
    field-symbols: <dyn_table> type standard table,
                   <g2> type ref to zcltest,
                   <g1> type ref to cl_gui_custom_container,
                   <actual_tab> type standard table,
                   <outtab> type table,
                   <fs1> type ANY,
                   <FS2> TYPE TABLE,
                   <fs3> type table,
                   <fs4> type table,
                   <fs5> type  table.
    class zcltest definition inheriting from cl_gui_alv_grid.
    define this as a subclass so we can access the protected attributes
    of the superclass cl_gui_alv_grid
      public section.
        types:  g4 type ref to cl_gui_custom_container.
        types:  g3  type ref to cl_alv_changed_data_protocol.
        data:   i_parent type g4,
                lr_rtti_struc TYPE REF TO cl_abap_structdescr, "RTTI
        zog like line of lr_rtti_struc->components. "RTTI
        types: struc like zog.
        types: struc1 type table of struc.
        methods:
           constructor
               importing i_parent type g4,
           disp_tab
               importing  p_er_data_changed type g3,
           create_dynamic_fcat
               importing zogt type struc1
               exporting it_fldcat type lvc_t_fcat.
    Protected section.
       data: stab type ref to data,
            wa_it_fldcat type lvc_s_fcat,
            c_index type sy-index.
    endclass.
    class zcltest implementation.
      METHOD constructor.
        CALL METHOD super->constructor
          EXPORTING
            i_appl_events = 'X'
            i_parent      = i_parent.
          endmethod.
      method disp_tab.
    mt_outtab is the data table held as a protected
    attribute in class cl_gui_alv_grid.
        assign me->mt_outtab->* TO <outtab>. "Original data
        assign p_er_data_changed->mp_mod_rows TO <FS1>.
        stab = p_er_data_changed->mp_mod_rows.
        assign p_er_data_changed->mt_inserted_rows to <fs3>.
        assign p_er_data_changed->mt_deleted_rows to <fs4>.
        assign p_er_data_changed->mt_mod_cells to <fs5>.
        assign stab->* TO <fs2>.
    do whatever you want with <outtab>
    contains data BEFORE changes each time.
    Note that NEW (Changed) table has been obtained
    already by  call to form
    check_data USING P_ER_DATA_CHANGED
    TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
    Entered data is in table defined by <fs2>
    In this method you can compare original and changed data.
    Easier than messing around with individual cells.
    do what you want with data in <fs2> validate / update / merge etc
      endmethod.
      method create_dynamic_fcat.
        loop at zogt into zog.
          c_index = c_index + 1.
          clear wa_it_fldcat.
          wa_it_fldcat-fieldname = zog-name .
          wa_it_fldcat-datatype = zog-type_kind.
          wa_it_fldcat-inttype = zog-type_kind.
          wa_it_fldcat-intlen = zog-length.
          wa_it_fldcat-decimals = zog-decimals.
          wa_it_fldcat-coltext = zog-name.
          wa_it_fldcat-lowercase = 'X'.
          if c_index eq 2.
            wa_it_fldcat-emphasize = 'C411'.
          endif.
          if c_index eq 3.
            wa_it_fldcat-emphasize = 'C511'.
          endif.
          append wa_it_fldcat to it_fldcat .
        endloop.
      endmethod.                    "create_dynamic_fcat
    endclass.                    "zcltest IMPLEMENTATION
    class lcl_grid_event_receiver definition.
      public section.
    note that zcltest inherits all of events etc from
    class cl_gui_alv_grid so specify event handler for
    zcltest.
    methods:
        handle_data_changed
             for event data_changed of zcltest
             importing  er_data_changed,
        toolbar
             for event toolbar of zcltest
             importing e_object
             e_interactive,
        user_command
             for event user_command of zcltest
             importing e_ucomm.
    endclass.
    class lcl_grid_event_receiver implementation.
      method handle_data_changed.
    code whatever required after data entry.
    various possibilites here as you
    can get back Cell(s) changed
    columns or the entire updated table.
    Data validation is also possible here.
    Note here the field sybol <g2> contains our
    instance of  class zcltest so we can now
    call any methods / access
    attributes of that class from this method
    in our event handler class.
        call method <g2>->disp_tab
          EXPORTING
            p_er_data_changed = er_data_changed.
      endmethod.                    "handle_data_changed
      method toolbar.
        data : ls_toolbar type stb_button.
        clear ls_toolbar.
        move 0 to ls_toolbar-butn_type.
        move 'EDIT' to ls_toolbar-function.
        move space to ls_toolbar-disabled.
        move 'Edit' to ls_toolbar-text.
        move icon_change_text to ls_toolbar-icon.
        move 'Click2Edit' to ls_toolbar-quickinfo.
        append ls_toolbar to e_object->mt_toolbar.
        clear ls_toolbar.
        move 0 to ls_toolbar-butn_type.
        move 'UPDA' to ls_toolbar-function.
        move space to ls_toolbar-disabled.
        move 'Update' to ls_toolbar-text.
        move icon_system_save to ls_toolbar-icon.
        move 'Click2Update' to ls_toolbar-quickinfo.
        append ls_toolbar to e_object->mt_toolbar.
        clear ls_toolbar.
        move 0 to ls_toolbar-butn_type.
        move 'EXIT' to ls_toolbar-function.
        move space to ls_toolbar-disabled.
        move 'Exit' to ls_toolbar-text.
        move icon_system_end to ls_toolbar-icon.
        move 'Click2Exit' to ls_toolbar-quickinfo.
        append ls_toolbar to e_object->mt_toolbar.
      endmethod.                    "toolbar
      method user_command.
        case e_ucomm .
          when 'EDIT'. "From Tool bar
            perform set_input.
            perform init_grid.
          when 'UPDA'. "From Tool bar
            perform refresh_disp.
            perform update_table.
          when 'EXIT'. "From Tool bar
            leave program.
        endcase.
      endmethod.                    "user_command
    endclass.                    "lcl_grid_event_receiver IMPLEMENTATION
    program data
    include <icon>.
    define any old internal structure NOT in DDIC
    types: begin of s_elements,
    anyfield1(20) type c,
    anyfield2(20) type c,
    anyfield3(20) type c,
    anyfield4(20) type c,
    anyfield5(11) type n,
    end of s_elements.
    data: wa_element type s_elements,
    wa_data type s_elements.
    Note new RTTI functionality allows field detail
    retrieval at runtime for dynamic tables.
    data:
            grid1 type ref to zcltest,
            grid_handler type ref to lcl_grid_event_receiver,
            c_dec2 type s_elements-anyfield5,
            wa_it_fldcat type lvc_s_fcat,
            it_fldcat type lvc_t_fcat,
            lr_rtti_struc TYPE REF TO cl_abap_structdescr, "RTTI
            lt_comp TYPE cl_abap_structdescr=>component_table,"RTTI
            ls_comp LIKE LINE OF lt_comp, "RTTI
            zog like line of lr_rtti_struc->components,  "RTTI
            struct_grid_lset type lvc_s_layo,
            l_valid type c,
            new_table type ref to data.
            types: struc like zog.
    data:  zogt type table of struc,
            grid_container1 type ref to cl_gui_custom_container,
            g_event_receiver type ref to lcl_grid_event_receiver,
            ok_code like sy-ucomm,
            i4 type int4.
    start-of-selection.
      call screen 100.
    module status_0100 output.
      if grid_container1 is initial.
        create object grid_container1
        exporting
        container_name = 'CCONTAINER1'.
        assign grid_container1 to <g1>.
        create object grid1
         exporting i_parent = grid_container1.
    we need reference to this instance so we can use
    Methods etc of zcltest class and alv (superclass)
    in our event receiver class.
         assign grid1 to <g2>.
        create object grid_handler.
        set handler:
        grid_handler->user_command for grid1,
        grid_handler->toolbar for grid1,
        grid_handler->handle_data_changed for grid1.
    Get the Internal table structure
        lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( wa_data ).
    Build field catalog just use basic data here
    colour specific columns as well
        zogt[] = lr_rtti_struc->components.
           call method grid1->create_dynamic_fcat
          EXPORTING
            zogt      = zogt
          IMPORTING
            it_fldcat = it_fldcat.
    Create dynamic internal table and assign
    to field symbol.
    Use dynamic field catalog just built.
      call method cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = it_fldcat
        IMPORTING
          ep_table        = new_table.
      assign new_table->* to <dyn_table>.
        perform populate_dynamic_itab.
        perform init_grid.
        perform register_enter_event.
    set off ready for input initially
        i4 = 0.
        call method grid1->set_ready_for_input
          EXPORTING
            i_ready_for_input = i4.
      endif.
    endmodule.                    "status_0100 OUTPUT
    module user_command_0100 input.
    *PAI not needed in OO ALV anymore as User Commands
    are handled as events
    *in method user_command.
    we can also get control if any data was entered
    and the ENTER is pressed by
    raising an event.
    Control then returns to method handle_data_changed.
    endmodule.                    "user_command_0100 INPUT
    form populate_dynamic_itab.
    load up a line of the dynamic table
      c_dec2 = c_dec2 + 11.
      wa_element-anyfield1 = 'Tabbies'.
      wa_element-anyfield2 = 'ger.shepards'.
      wa_element-anyfield3 = 'White mice'.
      wa_element-anyfield4 = 'Any old text'.
      wa_element-anyfield5 = c_dec2.
      append wa_element to <dyn_table>.
    endform.                    "populate_dynamic_itab
    form exit_program.
      call method grid_container1->free.
      call method cl_gui_cfw=>flush.
      leave program.
    endform.                    "exit_program
    form refresh_disp.
      call method grid1->refresh_table_display.
    endform.                    "refresh_disp
    form update_table.
    The dynamic table here is the changed table
    read from the grid
    after user has changed it
    Data can be saved to DB or whatever.
      loop at <dyn_table> into wa_element.
    do what you want with the data here
      endloop.
    switch off edit mode again for next function
      i4 = 0.
      call method grid1->set_ready_for_input
        EXPORTING
          i_ready_for_input = i4.
    endform.                    "update_table
    form set_input.
      i4 = 1.
      call method grid1->set_ready_for_input
        EXPORTING
          i_ready_for_input = i4.
    endform.                    "set_input
    form switch_input.
      if i4 = 1.
        i4 = 0.
      else.
        i4 = 1.
      endif.
      call method grid1->set_ready_for_input
        EXPORTING
          i_ready_for_input = i4.
    endform.                    "switch_input
    form init_grid.
    Enabling the grid to edit mode,
      struct_grid_lset-edit = 'X'. "To enable editing in ALV
      struct_grid_lset-grid_title = 'Jimbos Test'.
       call method grid1->set_table_for_first_display
        EXPORTING
          is_layout       = struct_grid_lset
        CHANGING
          it_outtab       = <dyn_table>
          it_fieldcatalog = it_fldcat.
    endform.                    "init_grid
    form register_enter_event.
      call method grid1->register_edit_event
        EXPORTING
          i_event_id = cl_gui_alv_grid=>mc_evt_enter.
    Instantiate the event or it won't work.
      create object g_event_receiver.
      set handler g_event_receiver->handle_data_changed for grid1.
    endform.                    "register_enter_event
    Have fun with this
    Cheers
    jimbo

  • How to capture user input for customer exit processing?

    I need to calculate the number of working days elapsed in the current fiscal quarter BASED on the USER INPUT on the reporting front.  i.e., say the fiscal quarter started on 1 July 2005 and if the user enters 10 July 2005, I should get the value 8 (Assume that Monday through Friday are all workdays).  If the user enters 12 July 2005, I should get 10.  I have written customer exits and know how to use factory calendar, but <b>THE CHALLENGE</b> is how do I <b>CAPTURE</b> the user input and use it in my exit?  During the varible definition, if I select the check box "Ready for input" then the customer exit is not being processed and unless I check that box I can't get a user entry!  If I look at the import values in the customer exit, I see i_t_var_range with type rrs0_t_var_range.  My strong feeling is that this parameter gets the user input, but I am unable to use it as the customer exit is not being called if I make the user to input the data.  Based on the empirical evidence, I felt that user input and customer exit can not co-exist!!  Please somebody prove me wrong and let me know how can I use the user input to process my "customer-exit" variable.  I would really appreciate any input from the BW community here.

    Hi Sameer,
    Most likely, I'm missing something, but I think that the answer is very simple.
    CASE I_VNAM.
    WHEN 'YOUR_CUSTOMER_EXIT_VAR'.
    IF I_STEP = 2. “ After selecting of input variable
    LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE
    WHERE VNAM = 'USER_INPUT_VAR'.
    CLEAR L_S_RANGE.
    L_S_RANGE-LOW = LOC_VAR_RANGE-LOW(4).
    APPEND L_S_RANGE TO E_T_RANGE.
    ENDLOOP.
    ENDIF.
    ENDCASE.
    In this typical user exit coding you have a user entered value in LOC_VAR_RANGE (originally in I_T_VAR_RANGE) and you construct your user exit variable value in E_T_RANGE.
    Best regards,
    Eugene
    Message was edited by: Eugene Khusainov

  • Calling report from a form with user input parameters

    Hello,
    I am new to Oracle reports. I have an application coded in 6i. I am currently running the application in Oracle Forms Builder 9i. There are also few reports which are called from the forms. Since the application was developed in 6i, the report was called using Run_Product. The forms pass a set of user parameters to the report using the parameter list pl_id. The syntax used was Run_Product(REPORTS, 'D:\Report\sales.rdf', SYNCHRONOUS, RUNTIME,FILESYSTEM, pl_id, NULL);
    I learnt that the Run_product doesnt work in 9i and we need to use run_report_object. I have changed the code to use run_report_object and using web.show_document () i am able to run the report from the form. There are 2 parameters that need to be passed from forms to reports. The parameters are from_date and to_date which the user will be prompted to enter on running the form. In the report, the initial values for these parametes are defined. So, the report runs fine for the initial value always. But when i try to change the user inputs for the form_date and to_date, the report output doesnt seem to take the new values, instead the old report with the initial values(defined in the report) runs again.
    Can someone give me the code to pass the user defined parameters to the report from the forms? I have defined a report object in the forms node as REPTEST and defined a parameter list pl_id and added form_date and to_date to pl_id and used the following coding:
    vrepid := FIND_REPORT_OBJECT ('REPTEST');
    vrep := RUN_REPORT_OBJECT (vrepid,pl_id);
    But this doesnt work.
    Also, Should the parameters defined in the forms and reports have the same name?

    Thanks for the quick response Denis.
    I had referred to the document link before and tried using the RUN_REPORT_OBJECT_PROC procedure and ENCODE functions as given in the doc and added the following SET_REPORT_OBJECT_PROPERTY in the RUN_REPORT_OBJECT_PROC :
    SET_REPORT_OBJECT_PROPERTY(report_id,REPORT_OTHER,' FROM_DATE='||:BLK_INPUT.FROM_DATE||' TO_DATE='||:BLK_INPUT.TO_DATE||' paramform=no');
    But this also dint work. Please help me understand what difference does setting paramform=no OR paramform=yes make?
    In the report, i have defined the user parameters as FROM_DATE and TO_DATE respectively so that they match the form datablock BLK_INPUT items FROM_DATE and TO_DATE.
    My WHEN_BUTTON_PRESSED trigger is as below:
    DECLARE
    report_id report_object;
    vrep VARCHAR2 (100);
    v_show_document VARCHAR2 (2000) := '/reports/rwservlet?';
    v_connect VARCHAR2 (30) := '&userid=scott/tiger@oracle';
    v_report_server VARCHAR2 (30) := 'repserver90';
    BEGIN
    report_id:= find_report_object('REPTEST');
    -- Call the generic PL/SQL procedure to run the Reports
    RUN_REPORT_OBJECT_PROC( report_id,'repserver90','PDF',CACHE,'D:\Report\sales.rdf','paramform=no','/reports/rwservlet');
    END;
    ... and the SET_REPORT_OBJECT_PROPERTY code in the RUN_REPORT_OBJECT_PROC procedure is as:
    PROCEDURE RUN_REPORT_OBJECT_PROC(
    report_id REPORT_OBJECT,
    report_server_name VARCHAR2,
    report_format VARCHAR2,
    report_destype_name NUMBER,
    report_file_name VARCHAR2,
    report_otherparam VARCHAR2,
    reports_servlet VARCHAR2) IS
    report_message VARCHAR2(100) :='';
    rep_status VARCHAR2(100) :='';
    vjob_id VARCHAR2(4000) :='';
    hidden_action VARCHAR2(2000) :='';
    v_report_other VARCHAR2(4000) :='';
    i number (5);
    c char;
    c_old char;
    c_new char;
    BEGIN
    SET_REPORT_OBJECT_PROPERTY(report_id,REPORT_COMM_MODE,SYNCHRONOUS);
    SET_REPORT_OBJECT_PROPERTY(report_id,REPORT_FILENAME,report_file_name);
    SET_REPORT_OBJECT_PROPERTY(report_id,REPORT_SERVER,report_server_name);
    SET_REPORT_OBJECT_PROPERTY(report_id,REPORT_DESTYPE,report_destype_name);
    SET_REPORT_OBJECT_PROPERTY(report_id,REPORT_DESFORMAT,report_format);
    SET_REPORT_OBJECT_PROPERTY(report_id,REPORT_OTHER,' FROM_DATE='||:BLK_INPUT.FROM_DATE||' TO_DATE='||:BLK_INPUT.TO_DATE||' paramform=no');
    hidden_action := hidden_action ||'&report='||GET_REPORT_OBJECT_PROPERTY(report_id,REPORT_FILENAME);
    hidden_action := hidden_action||'&destype='||GET_REPORT_OBJECT_PROPERTY(report_id,REPORT_DESTYPE);
    hidden_action := hidden_action||'&desformat='||GET_REPORT_OBJECT_PROPERTY (report_id,REPORT_DESFORMAT);
    hidden_action := hidden_action ||'&userid='||get_application_property(username)||'/'||get_application_property(password)||'@'||get_application_property(connect_string);
    c_old :='@';
    FOR i IN 1..LENGTH(report_otherparam) LOOP
    c_new:= substr(report_otherparam,i,1);
    IF (c_new =' ') THEN
    c:='&';
    ELSE
    c:= c_new;
    END IF;
    -- eliminate multiple blanks
    IF (c_old =' ' and c_new = ' ') THEN
    null;
    ELSE
    v_report_other := v_report_other||c;
    END IF;
    c_old := c_new;
    END LOOP;
    hidden_action := hidden_action ||'&'|| v_report_other;
    hidden_action := reports_servlet||'?_hidden_server='||report_server_name|| encode(hidden_action);
    SET_REPORT_OBJECT_PROPERTY(report_id,REPORT_OTHER,'pfaction='||hidden_action||' '||report_otherparam);
    -- run Reports
    report_message := run_report_object(report_id);
    rep_status := report_object_status(report_message);
    IF rep_status='FINISHED' THEN
    vjob_id :=substr(report_message,length(report_server_name)+2,length(report_message));
    message('job id is'||vjob_id);pause;
    WEB.SHOW_DOCUMENT(reports_servlet||'/getjobid'||vjob_id||'?server='||report_server_name,' _blank');
    ELSE
    --handle errors
    null;
    END IF;
    In the code - " hidden_action := hidden_action ||'&'|| v_report_other; " in the RUN_REPORT_OBJECT_PROC procedure above, how do i make sure that the v_report_other variable reflects the user input parameters FROM_DATE and TO_DATE ??? v_report_other is initialised as v_report_other VARCHAR2(4000) :=''; in the procedure. Will ensuring that the v_report_other contains the user input parameters FROM_DATE and TO_DATE ensure that my report will run fine for the input parameters?
    Thanks in advance.
    Edited by: user10713842 on Apr 7, 2009 6:05 AM

Maybe you are looking for