Home > AS/400 Tips > iSeries programmer tips > "CLEAR" advantage over resetting work fields
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

"CLEAR" advantage over resetting work fields


John Kohan, Search400 expert
08.14.2002
Rating: -4.00- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



John Kohan

At times we need to reset the value of work fields, data buffers and screen fields. If a field is an alphanumeric type, then we may move "*BLANKS" when we want it "reset". If a field is numeric, then we may "Zero Add" "*ZEROS" to the field.

But the "CLEAR" operation code provides much more flexibility. By using the "CLEAR" operation code, the fields reset to their default initialization value depending on field type (numeric, character, graphic, UCS-2, indicator pointer, or date/time/timestamp). This way you just "CLEAR" the field and let the computer reset it to the proper value.

In a single occurrence data structure, all fields are cleared in the order in which they are declared within the structure. For multiple occurrence data structures you can clear the "current" table element or if you specify "*ALL", then all elements are reset. The same holds true for arrays. If you clear ARRAY(1), then element one of the array is cleared. But if you clear ARRAY, then all the elements in the array are cleared.

You may also clear record formats on screens. If you are writing to a subfile with 10 workflields, you can clear the "SUBFILE" record format of the screen and all 10 records are reset. They can be a mix of alphanumeric and numeric, the CLEAR operation will deal with it.

You may also clear record formats of files. If you CLEAR the record format of a physical or logical file, then all the fields are reset to their default initialization value. You may also specify an optional value of *NOKEY and all the fields are cleared EXCEPT the key fields. This comes in handy when you read the last record in a file to get the last "key" used, add one to the value and clear with *NOKEY. You end up with a new initialized record with the key value already set.

So no matter what type of field, array, data structure or file, the CLEAR operation code will reset everything to the default value. The code becomes much easier to read, since you can clear whole records in one statement.

-----------------------------------------
About the author: John Kohan is a senior programmer analyst at CT Codeworks.

==================================
MORE INFORMATION
==================================



iSeries Security - Security Tools, Physical Security and System Security
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts