.st0{fill:#FFFFFF;}

RPG Built-In Functions %BIF 

 October 10, 2008

By  NickLitten

When IBM introduced RPG IV (RPGLE) back in the mid 90’s, most of the RPG III opcodes were converted into built in functions. This makes for more readable code and efficient programming. The built in functions each do a particular function just like any opcode would have done. Since the built in functions are provided by the system itself, all the error handling etc is done by the system itself and you are given just the errors.

When we learn RPGLE procedures, we will see that the built in functions are very similar to procedures. Within the %BIF itself, ‘arguments’ (the important bits defining what the BIF is doing) are denoted by a colon. Here is an example:

// Look on a file called 'SOMEFILE" and if that key 'CompanyCode' is found then do something...
 Chain CompanyCode SOMEFILE
 If %Found(SOMEFILE)

Of course, we can get complex and use %BIFS for some really neat functions. All in one line of code this operation is saying – take the value #STRDATE which is *MDY format and convert it to *CYMD then make that date variable into a 7 long alpha character field before finally turning it into a 7,0 numeric value (which is how the dates are stored on the files in this program).

// convert screen dates from MMDDYY to 7,0 numeric in CYYMMDD format 
 =%dec(%char(%date(#StrDate:*mdy):*cymd0):7:0);

Some important built in functions are given in the list below.

RPGIV Built-in fucntion Action Performed

  • %Dec Converts a valid character value into a numeric value of specified size.
  • %Char Converts a numeric value into a character value.
  • %Date Create a date in the specified format. Return the current date if no parameter specified.
  • %LookUp Returns the position of a value in an array. If the search value is not found in the lookup array, 0 is returned.
  • %XLate Replaces characters of a string with predefined characters. Used mainly for case conversion of letters (From Capital to Small etc.)
  • %XFoot Returns the sum of all the array elements of an array

NickLitten


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"cff50":{"name":"Main Accent","parent":-1},"a344d":{"name":"Accent Transparent","parent":"cff50"}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"cff50":{"val":"var(--tcb-skin-color-0)"},"a344d":{"val":"rgba(46, 138, 229, 0.85)","hsl_parent_dependency":{"h":210,"l":0.54,"s":0.78}}},"gradients":[]},"original":{"colors":{"cff50":{"val":"rgb(0, 178, 255)","hsl":{"h":198,"s":1,"l":0.5}},"a344d":{"val":"rgba(0, 178, 255, 0.85)","hsl_parent_dependency":{"h":198,"s":1,"l":0.5}}},"gradients":[]}}]}__CONFIG_colors_palette__

Get In Touch

Iā€™m always looking for awesome input, feedback and critique!

>