Sorry, you do not have permission to ask a question, You must login to ask a question.

Sorry, you do not have permission to ask a question.

brainchime.com

brainchime.com

brainchime.com Navigation

  • Home
  • About Us
  • Contact Us

Mobile menu

Close
  • Home
  • Categories
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags

brainchime.com Latest Questions

Admin
Admin
Asked: October 9, 20242024-10-09T07:47:05+05:30 2024-10-09T07:47:05+05:30In: IBM i

How to retrieve call stack information in RPG program?

How do you retrieve the call stack information in the rpgle program? For example, if we call pgm1, we want to know who called it or look for a particular program in the call stack. Is there any way to check the program call stack? Who is the program’s caller who called this program or whether a particular program is in the call stack so that we can build logic based on call stack program information?

as400rpg
  • 0
  • 0
  • 22
  • 5
  • Share
    • Share on Facebook
    • Share on Twitter
    • Share on LinkedIn
    • Share on WhatsApp

Related Questions

  • what is level check error and how to resolve level check error?
  • What are AS400 systems. Please provide a introduction of AS400 systems?
  • Is there any online server available for practicing on AS400 system?
  • What are the menus available in AS400?
  • What is subsystem in AS400?
  • How to copy a save file from IFS to a library?
  • How to transfer savf from as400 to pc?
  • How to copy ifs file to another directory?
  • How to copy savf from ifs to pc?
  • How to copy ifs file to physical file?
  • How to copy save file to ifs?
  • How to copy spool file to ifs?
  • How to copy physical file to ifs?
  • How to copy file from pc to IFS?
  • How to download spool file from AS400?
  • How do I delete a library in AS400?
  • How do I copy data from AS400 to excel?
  • What is library in AS400?
  • How to find all the source physical file available in AS400?
  • How to find all libraries in AS400?
  • How to change the library list in AS400?
  • What is access path in AS400?
  • What is the difference between source physical file and physical file in as400?
  • how to find the source file of an object in as400?
  • how to change record length of source physical file in as400?
  • What is cpf4174 error in as400?
  • What is the use of varying keyword in rpgle?
  • What is DDS in AS400?
  • What is the difference between PF and LF in as400?
  • Why do we use CHGPF command in AS400?
  • how to create physical file in as400?
  • What are the data types supported by physical files in AS400?
  • how to add data in physical file in as400?
  • how to view journal entries in as400?
  • what is the use of ovrdbf in as400?
  • What is an array in AS400?
  • what is a data queue in as400 and why do we use data queue?
  • How to run stored procedure in AS400?
  • How to resolve session and device error in AS400?
  • how to check as400 system values?
  • How to check triggers on a file in as400?
  • How to find damaged objects in AS400?
  • what is module in as400?
  • How to create binding directory in as400?
  • how to create ifs folder in as400?
  • What is ASP in AS400?
  • What is JOBQ and how to create a JOBQ in AS400?
  • What is PSDS in AS400?
  • What is SEU in AS400 and why do we use it?
  • What is the multi-format logical file in AS400?
Leave an answer

Leave an answer
Cancel reply

Browse
Browse

Choose from here the video type.

Put Video ID here: https://www.youtube.com/watch?v=sdUUx5FdySs Ex: "sdUUx5FdySs".

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Admin
    Admin
    2024-10-09T07:57:31+05:30Added an answer on October 9, 2024 at 7:57 am

    We can use retrieve call stack API (QWVRCSTK) to retrieve the call stack information or the presence of a specific program in the call stack or find the calling program.

    I was searching for it more, and I just discovered that IBM has launched a new table function, STACK_INFO, that does the same job for us as QWVRCSTK API does. It seems to me that retrieving call stack information using the SQL table function stack_info is quite simple, as it allows us to use the SQL select to retrieve a record for each entry in the call stack for a specific thread in a job.

    You can use SQL to retrieve program stack information. The stack_info table function does the same task for us as done by the Display Job (DSPJOB) CL command and the Retrieve Call Stack (QWVRCSTK) API. table function can be used in simple SQL select statements. By the way, it works for all types of call stacks such as OPM, ILE, pase, java, and lic stack.

    This table function requires 2 input parameters namely JOB_NAME which is the qualified name of the job, * is a current job, and THREAD_ID which means all the information from all threads gets returned. The default is INITIAL.

    For example, passing qualified job name in table function stack-info and thread as ALL to select all rows of this specific job for all threads.

    select * from table(qsys2.stack_info('JobNumber/User/JobName','ALL'))
    

    or passing the current job (*) in the table function stack-info and thread as ‘ALL’ to select all rows of this specific job for all threads.

    select * from table(qsys2.stack_info('*','ALL'))

    sample rpgle program to retrieve call stack information using SQL table function stack_info.

         d psds           sds                                      
         d  curpgmname       *PROC                                                        
                                                                   
         Dstackdsarr       DS                  dim(999) qualified  
         D l_ordpos                      10i 0                     
         D l_entrytype                    4A   varying             
         D l_stmtid                     109A   varying             
         D l_pgmname                     10A   varying             
         D l_modname                     10A   varying             
         D l_procname                  4096A   varying             
          *                                                        
         D l_loop          S              5P 0 inz(1)              
         d callerpgm       s             10a                       
          /free                                                    
           exec sql                                                
           declare getstackinfo cursor for                         
           select ordinal_position,                           
           coalesce(entry_type,' '),                          
           coalesce(statement_identifiers,' '),               
           coalesce(program_name,' '),                        
           coalesce(module_name,' '),                         
           coalesce(procedure_name,' ')                       
           from table(qsys2.stack_info('*', 'ALL'))           
           where (ordinal_position <= (select ordinal_position
           from table(qsys2.stack_info('*', 'ALL'))           
           where program_name = :curpgmname                   
           fetch first row only));                            
                                                              
           exec sql                                           
           open getstackinfo;                                 
                                                              
           exec sql                                           
           fetch getstackinfo for 999 rows                    
           into :stackdsarr;                                  
                                                              
           exec sql                                           
           close getstackinfo;                                
                                                              
           for l_loop = 1 by 1 to %elem(stackdsarr);          
            if stackdsarr(l_loop).l_pgmname <> ' ';           
             if (curpgmname <> stackdsarr(l_loop).l_pgmname); 
               callerpgm = stackdsarr(l_loop).l_pgmname;      
               leave;                                         
             endif;                                           
            else;                                             
             leave;                                           
            endif;                                            
           endfor;                                            
                                                              
           dsply callerpgm;                                   
                                                              
           return;                                            
          /end-free                                         
      • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
  2. Admin
    Admin
    2024-10-09T07:51:58+05:30Added an answer on October 9, 2024 at 7:51 am

    We can retrieve call stack information using the retrieve call stack (QWVRCSTK) api. We use this retrieve call stack api whenever we want to find the calling program name. We use this api when we want to execute or skip some logic in the current program in the call stack based upon the calling program means who called this program. The thread’s most recent call is indicated by the first call stack record that is returned. Here is the sample program that retrieves the call stack information and finds the calling program name.

        d psds           sds                                      
         d  curpgmname       *PROC                                 
         d  curjobname           244    253                        
         d  userid               254    263                        
         d  jobnumber            264    269                        
                                                                   
         d retrievecallstack...                                    
         d                 PR                  Extpgm('QWVRCSTK')  
         d recvar                     32767a                       
         d lenrecvar                     10I 0                     
         d fmtrcvvar                      8a   CONST               
         d jobidinfo                     56a                       
         d fmtjobidinfo                   8a   CONST               
         d errorcode                     15a                       
                                                                   
         d recvar          DS         32767                        
         d  BytesAvl                     10I 0                     
         d  BytesRtn                     10I 0                     
         d  Entries                      10I 0                     
         d  Offset                       10I 0                     
         d  EntryCount                   10I 0                     
                                                                   
         d jobidinfo       DS                                      
         d  JobName                      26a   Inz('*')            
         d  Jobid                        16a                       
         d  Reserved                      2a   Inz(*loval)         
         d  ThreadInd                    10I 0 Inz(1)              
         d  ThreadId                      8a   Inz(*loval)         
                                                                   
          *  Call Stack Program Names                              
         d Entry           DS           256                        
         d  EntryLen                     10I 0                     
         d  ReqstLvl                     10I 0 Overlay(Entry:21)   
         d  PgmName                      10a   Overlay(Entry:25)   
         d  PgmLib                       10a   Overlay(Entry:35)   
                                                                   
         d recvarlen       s             10I 0 Inz(%size(recvar))  
         d errorcode       s             15a                       
         d callerpgm       s             10a       
         d loop            s             10I 0     
          /free                                    
            retrievecallstack(recvar:              
                              recvarLen:           
                              'CSTK0100':          
                              jobidinfo:           
                              'JIDF0100':          
                              errorcode);          
                                                   
            For loop = 1 to EntryCount;            
               Entry = %subst(recvar:Offset + 1);  
               If (curPgmName  <> Pgmname);        
                  callerpgm = PgmName;             
                  leave;                           
               Endif;                              
               Offset = Offset + EntryLen;         
            Endfor;                                
                                                   
            dsply callerpgm;                       
                     
            return;  
          /end-free  

    Here, psds is declared to fetch the current job and program information. Jobname is passed as *, indicating the current job. You can change the following check If (curPgmName Pgmname); in the program to check the provided program’s call stack entry or the call stack entry preceding it, which is the caller of the supplied program. So we can change conditions like If (Pgmname = ‘TESTPGM’); which means you are checking for the specified program in the call stack entry.

      • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp

Sidebar

Statistics

  • Questions 143
  • Answers 177
  • Comments 0
  • Popular
  • Answers
  • Admin

    Why do we use OVERLAY keyword in data structure subfields ...

    • 12 Answers
  • Admin

    How to call sql stored procedure with output parameter from ...

    • 6 Answers
  • Admin

    How to use declare global temporary table statement in RPGLE?

    • 5 Answers
  • Admin
    Admin added an answer CPF4131 is a record format level check error. This indicates… October 18, 2024 at 1:58 am
  • Admin
    Admin added an answer To open the command prompt with administrator rights you can… October 17, 2024 at 12:27 am
  • Admin
    Admin added an answer In AS400, "AS" stands for Application system. This article discusses… October 13, 2024 at 12:49 pm

Related Questions

  • Admin

    what is level check error and how to resolve level ...

    • 1 Answer
  • Admin

    What are AS400 systems. Please provide a introduction of AS400 ...

    • 1 Answer
  • Admin

    Is there any online server available for practicing on AS400 ...

    • 1 Answer
  • Admin

    What are the menus available in AS400?

    • 1 Answer
  • Admin

    What is subsystem in AS400?

    • 1 Answer

Trending Tags

.htaccess (1) as400 (123) bing-webmaster (2) control-language (12) db2 (33) ftp (8) google-adsense (1) google-search-console (3) https-redirect (1) iasp (4) ifs (22) jar (4) operations (3) php-my-admin (1) qshell (3) robots.txt (4) rpg (26) stored-procedure (3) stroed procedure (1) triggers (1) yoast (4)

Explore

  • Home
  • Categories
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags

Footer

BrainChime

BrainChime is a blog that posts question-and-answer-based format articles on diverse topics and engages in discussions by allowing people to provide answers/comments without the need to register and log in.

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • FAQs
  • Categories
  • Tags

© 2024 BrainChime. All Rights Reserved
by BrainChime.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.