RPGWEB and simple web pages

RPGWEB and simple web pages

Javascript frameworks and web 2.0 are a big deal however, you don’t always need them for something simple. Or perhaps it is a simple internal tool for your company, and a quick HTML page fits your needs perfectly. Well, embedded RPG templates have been added to RPGWEB. Let’s take a quick look at an example.

       ctl-opt bnddir('RPGWEB') option(*nodebugio:*srcstmt);

      /include RPGWEB/QRPGLESRC,RPGWEB_H

       dcl-ds app likeds(RPGWEBAPP) inz;

       RPGWEB_setView(app : '/home/dlong/web_apps/public');

       RPGWEB_get(app : '/test' : %paddr(TEST_index));
       RPGWEB_start(app: 3031);

       *inlr = *on;
       return;

       dcl-proc TEST_index;
         dcl-pi *n likeds(RPGWEBRSP);
           request likeds(RPGWEBRQST);
         end-pi;
         dcl-ds response likeds(RPGWEBRSP);

         dcl-ds data qualified;
           field1 char(50);
           field2 packed(11:0);
         end-ds;

         data.field1 = 'Daniel';
         data.field2 = 8675309;

         RPGWEB_setStatus(response : HTTP_OK);
         RPGWEB_setBody(response : RPGWEB_render(app : 'index' : data));

         return response;
       end-proc;

We can see a couple of new procedures. RPG_setView and RPGWEB_render. RPG_setView sets the location in the IFS where the RPG template is to be found. The RPGWEB_render method passes the data to the template, and then creates HTML page, then returns it. The template should always end in `.erpg`. So here we are looking for the file `index.erpg`. We are passing the application so we will know where to look for the template and then the data that is used in the template. The following is the `index.erpg` that for the example.

<%= 
  dcl-ds data qualified;
    field1 char(50);
    field2 packed(11:0);
  end-ds;
  data = RPGWEB_injected_data();
=%>

<html>
  <%
    if 1 = 0;
      RPGWEB_write('Hello World');
    else;
      RPGWEB_write('Hello  ' + %trim(data.field1));
    endif;
  %>
  <br />
  <%
    RPGWEB_write('<br /> ' + %char(data.field2));
  %>
</html>

At the top of the template, you see the data structure defined again here. I am trying to work on this so you don't have to redefine it. For now, this works. You see we grab the injected data and push it into this data data structure. then we can use it inside of the logic blocks. The output is super lame, but it serves the purpose of showing what can be done.

No alt text provided for this image

This uses standard RPG concepts. This isn't super fast right now, but we are working on that. I hope you find this feature helpful. Lemme know. If you build something with it, I would like to see it. Check the project out at the following on GitHub. Link below.


To view or add a comment, sign in

More articles by Daniel Long

  • SQL vs RLA - Round 2

    Wow, thanks so much for your feedback and response to the last article. That was so cool! In the last article we found…

    4 Comments
  • SQL vs RLA

    As RPG programmers processing database records is one of our highest priorities. Doing it well and efficiently can lead…

    34 Comments
  • ALIAS: Not just for a Superhero

    My grandma used to say that the only thing good about the good old days..

    5 Comments
  • Free IBMi UI Testing

    I am not a fan of DSPF for UI, however, there are still tons of them running around in the wild. So, we can't just…

  • Clean Your Code Up!

    Let's talk about cleaning code. How do you clean code? What is clean code? Bob Martin(Uncle Bob) is the guru on all…

  • Modernization Of Code - Part 1

    I thought it might be kinda nice to try something with you all. Let's modernize a system together.

    1 Comment
  • Abstraction with Open Access

    Ok. So I came across a problem that I am sure you likely have come across as well.

    2 Comments
  • Featuring Feature Flags

    Stop me if you have heard this one before. You are ready to install the latest feature you have been working and the…

    1 Comment
  • Thread Safety - Not just for sewing machines

    So let's talk about something that happened to me on a recent project. I stepped into a thread safety issue and made a…

    2 Comments
  • Why Should You Refactor Working Code?

    Let's be honest we all have code that is terrible to read, but it still works so it is still running. The problem with…

    3 Comments

Others also viewed

Explore content categories