IBM Support

Creating a Stored Procedure to call an RPG program using QSYGETPH API

Troubleshooting


Problem

Тhe steps to creatе a stored procedure that calls an RPG program with QSYGETPH API.

Resolving The Problem

The following is an example on how to create a stored procedure that calls an RPG program with the use of QSYGETPH API.
 
Disclaimer: This document is an example. IBM takes no responsibility for its correctness.

The STRSQL command is used to create the stored procedure.

The command to create the procedure in STRSQL:
 
CREATE OR REPLACE PROCEDURE yourlib.VALIDAPASS (    
IN USUARIO CHAR(10) ,                    
IN "PASSWORD" CHAR(10) ,                
INOUT CONFIRMA CHAR(11) )                
LANGUAGE RPGLE                          
SPECIFIC yourlib.VALIDAPASS            
NOT DETERMINISTIC                        
NO SQL                                  
CALLED ON NULL INPUT                    
EXTERNAL NAME '<yourlib>/CHKPWDBM1'        
PARAMETER STYLE GENERAL WITH NULLS;


Note: The length of Longi and ccsid can be changed. The API documentation says that the last two required parameters must be defined as 4(bin); in ILE RPG IV, a 4 bytes binary is Int(10).  If your password is only 8 characters long, the size of WCONTR 8 has to be changed. The password parameter for the API has to be the same size as your actual password. This sample is just a proof of concept and no error handling has been added.

ILE RPG IV Program name is CHKPWDBM1:
**FREE
 Dcl-S Longi           Int(10)         inz(X'00000008');
 Dcl-S ccsid           Int(10)         inz(37);
 Dcl-Ds ERRCDE Len(272);
    BYTPRO          BinDec(9:0)     Pos(1) INZ(256);
    BYTAVL          BinDec(9:0)     Pos(5) INZ(64);
    EXCPID          Char(7)         Pos(9);
    RSVD            Char(1)         Pos(16);
    EXCPDT          Char(256)       Pos(17);
 End-Ds;
 Dcl-S PROFIL          Char(12);
 // Prototype for CHKPWDBM
 Dcl-Pr Pgm_CHKPWDBM1 ExtPgm('CHKPWDBM1');
    WUSUAR          Char(10);
    WCONTR          Char(8);
    ERRORA          Char(11);
 End-Pr;
 // Procedure interface for CHKPWDBM1
 Dcl-Pi Pgm_CHKPWDBM1;
    WUSUAR          Char(10);
    WCONTR          Char(8);
    ERRORA          Char(11);
 End-Pi;
 // Prototype for QSYGETPH
 Dcl-Pr Pgm_QSYGETPH ExtPgm('QSYGETPH');
    WUSUAR          Char(10);
    WCONTR          Char(8);
    PROFIL          Char(12);
    errcde          LikeDs(errcde);
    longi           Int(10);
    ccsid           Int(10);
 End-Pr;
 //
 //
 Clear PROFIL;
 Pgm_QSYGETPH(WUSUAR : WCONTR : PROFIL : errcde : longi :
       ccsid);
 //
 If BYTAVL <> 0;
    EXCPID='CPF22E2';
    ERRORA='PWD INVALID';
 Else;
    ERRORA='PWD VALID';
 EndIf;
 *INLR = '1'; 

Compile using CRTBNDRPG.

To do a test you can use Run SQL Scripts from an ACS 5250 Session.

image-20241127170559-1

CALL YOURLIB.validapass('USER','PASSWORD','?');

For the IN/OUT parameter, a "?" is used.

image-20241127170727-2


image-20241127170818-3

[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m0z0000001iICAAY","label":"IBM i Db2-\u003EStored Procedures"},{"code":"a8m0z0000000CHtAAM","label":"Programming ILE Languages"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]

Historical Number

467229267

Document Information

More support for:
IBM i

Component:
IBM i Db2->Stored Procedures, Programming ILE Languages

Software version:
All Versions

Operating system(s):
IBM i

Document number:
636205

Modified date:
27 November 2024

UID

nas8N1014053

Manage My Notification Subscriptions