1999-November = This document started by Al Macintyre Intent is both QUERY TECHNIQUES summary how-to and by example - where do we have worth copying? Other relevant documents for this kind of thinking ================================================== COSTXTRACT in BP4TCDO/BPCSDOC = Navigating BPCS Costs CSPYQRYHOW in BP4TCDO/BPCSDOC = Guidance to Query Creators for creating Your variant of Query CSPY HIT VAR HOWFLOBPCS in BP4TCDO/BPCSDOC = Navigating BPCS in general ORDSCPEFF in BTESTSRC/QDOCSRC = Scrap Reports for Quality Control QRYDBPNAV8 in BP4TCDO/BPCSDOC = Navigating BPCS Data Base Files for Query Creators TIPROGNAME in BP4TCDO/BPCSDOC = Navigating BPCS existing software options if you want to do "X" look up logically for names of reports & inquries available We sometimes notice slick techniques being used by some query, then when we want to do the same kind of thing in another query, we have sometimes forgotten where that neat discovery was located. This document attempts to portray by type of technique, which queries to look in to see how to learn how to work that. --------------------------------------------------------ABSOLUTE VALUE A tip in Dec 2k News/400 Magazine explains how to sort on ABSOLUTE VALUE in Query/400 by squaring the field on which you want to sort. You must select the squared result to sort on it. But don't print the result - in the column descriptions, set the header to *NONE and the spacing and field length to zero. You can print the original field (with or without the sign) instead of its squared result. ALPHA CHARACTER - also see FIELD TYPES ALPHA TO NUMERIC - see FIELD TYPES APPEARANCE NICE - see PRETTY PRINT BLANK RECORDS ... why would we have blank records in BPCS files? Check UNMATCHED ... we can get the appearance of blank records if JOIN-3 is reversed. BOM no match usages ... see query ENG260L initially Al thought that IIM"s INSEQ zero might be sufficient - but an issue is how we match multiple files ... see UNMATCH - BPCS Menu CALL a Query see end of this inventory of Techniques for this related topic. BPCS naming conventions ... creating queries can go faster by people who understand how BPCS has named files and how to use command line to view names of groups of files. Try DSPLIB to get library list ... scroll to BP4CDT this library should contain all live environment data files. Place digit 5 in front of that library to display file list. Rapidly scroll through --- there is a way to print the list which runs to about 50 pages --- ask Al to get you one. You should notice that there is a correlation between first letter of file name & the kind of application the file is for. BPCS naming conventions ... FILES summary reference list Two of Unbeaten Path Manuals on BPCS have reference lists of files by application with what some codes mean. You might want to photocopy the 2-3 pages covering the areas you most often need to do queries on. Check Chapter X of BPCS Manual on Engineering & Costing & Inventory and Chapter T of the Manual focused only on Inventory. BPCS naming conventions ... FILES summary story on FILES Physical files are designated by ABB where: A is the one letter product code; BB is a file code. Examples: IIM: Item master file (I = inventory) ILN: Lot master (I = inventory) ECH: Customer order header (E = customer orders) You can find the "one letter product code" for many applications via the BPCS manuals such as those from Unbeaten Path and via vanilla menu named SSAYNN where: SSA = "SSA" Y = The one letter product code; then number sequence. Accounting Files = A-Payable B-Billing C-Cost_etc. G-GenLed OCash Q-Assets R-Receivables Bar Code system will use Files starting with "N" Customer Order & Shipping Files start with "E" Promotions & Deals = "P" S-Sales & Invoice History Engineering & Inventory Files start with "I" & "M" Planning Files = D-DRP K-MPS+MRP L-Capacity Purchasing Files start with "H" Shop Floor Production Files start with "F" JIT files = "V" System Files such as parameters start with "Z" So with the above clues & WRKOBJ letter asterisk F4 limit to *FILES or some other system tool, you can see a list of just the files relevant to a particular application. BPCS naming conventions ... On-Line Documentation LOGIC Manual talks about this subject in more detail than anyone outside MIS needs to know. - - - - - - - - - - - - BPCS User Menu CALL a Query via a CL Program see end of this inventory of Techniques for this related topic. BREAKS - See sub-total level break printing CALL a Query from a BPCS Menu see end of this inventory of Techniques for this related topic. - - - - - - - - - - - - CASE as in UPPER or LOWER CASE can become a problem if we have data that mixes up cases Select number 6 "Collating Sequence" on the "Main WRKQRY Definition Options" inside a Query Select option 5 "System Sort Sequence" on the "Select Collating Sequence Panel" Leave the 2 lines on bottom blank & press enter You get a new screen defaulting to *JOBRUN on bottom and we put option 3 "Shared" on the field up top What this *JOBRUN is = the basis of the SORT and LANGUAGE and the above combination of selections means that CASE can be ignored not only for sort sequence but also other attributes of the Query like Selection criteria. Select bottom "Processing Options" on the "Main WRKQRY Definition Options" inside a Query First screen is "Specify Processing Options" Bottom of that should be "Y" for "Use collating sequence for all character comparisons" An example of how we might use this capability Select Records where CUSNAM LIKE '%smith%' This would catch all cases of smith irrespective of case such as SMITH Smith sMitH - - - - - - - - - - - - CEILINGS ... simple numbers can be up to 31 digits "length" when floating point & precision is not involved Joining files goes up to 32 files in one query See JOINING CHARACTER - also see FIELD TYPES CL Program CALL a Query from a BPCS User Menu see end of this inventory of Techniques for this related topic. - - - - - - - - - - - - COMMAND LINE access to WRKQRY is quite dangerous for users inexperienced with how not to mess up Query and we would like to discourage this where practical i.e. identify circumstances where users feel they need to use work query as opposed to running something off a menu then figure out how to get them what they want off menu. From any BPCS user menu ... run INVENGVIEW which runs one of the XQRYs and you see a list of our queries alphabetized by the title description of the query then after selecting the query you desire run INVENGQRY which is RUNQRY from menu with you keying in which query you going to run The data on queries available is from an *OUTFILE regenerated each evening so it won't show latest input People who create queries & research data base may need continuation of command line access but some of the tools we use, such as RUNQRY *N _____ file name _____ *YES could go into something similar to the Query View above initially same pattern a) view a list of files b) runqry access file of your choics later see if I can create a command where F4 on the file name elicits access to list of files Where there are performance issues ... query needs to go on JOBQ the expedient thing is for user to change WRKQRY then to batch from within WRKQRY and IT as time permits convert software to HLL version We have recurring situation where people might want to do a DATE range & have that get to JOBQ ... a tip at AS/400 network 1. Prompt screen standard format to get & validate dates 2. Just before RUNQRY = create work file & populate with that date 3. Use that file in query on "Specify File Selections" and date on the screen "Select Record" - - - - - - - - - - - CONCATENATION means "joining" 2 or more fields together - into 1 larger field in which the "joined" fields are contiguous, which means adjacent. We often need to do this for DATE MATH. CONCATENATION examples - see queries ECG ENGSFC* - - - - - - - - - - - - COST ... This is a complex topic easily misconstrued details. New Document started just to try to explain the intricacies & nuances there. COSTXTRACT in BP4TCDO/BPCSDOC = Navigating BPCS Costs COST ... at one time there was cost bucket ZERO containing total of all other buckets for the same combination of other cost fields, but Al no longer knows if this reality has kept itself current automatically. COST ... a lot of queries use combinations of cost buckets & cost set to determine what data to input for purpose of calculating cost. However, when we want to total several cost buckets into a single line of a query in which several records are also being combined into one line this is more than is doable with a single query ... we need to construct a string of queries, some creating work files as input and this kind of thinking is not conduscive to pop-up run time choices. COST ... IIM.ISCST has been used by some people for standard cost but TIM determined that some items have a valid cost on INV300 which is missing from ISCST ... INV300 was inspected to find where it gets cost & traced to a call to CST590 in which Al thought the logic was too complex to transcribe to a Query ... see CSTOPS_RPG program for example. COST BY FACILITY apparently works in Query ENG260L in which CIC contributes cost for specified facility and ILI contributes inventory for specified warehouse range - - - - - - - - - - - - COUNTING ... How many lines on this report ... how many orders ... etc. Example how to do this = Query SFCEVA3 CURRENT - also see FIELD TYPES CURRENT ... Select stuff based on some relationship with CVRRENT date as of when the Query actually runs ... examples of this technique see queries ECG SFCUPDFRT SFCUPDIIM SHIPSHEET - - - - - - - - - - - - CUSTOMER ITEM ... Many End Items (Item Type 1) contain part of the Customer number that they are made for within the IDRAW field of ITEM MASTER File IIM. Suppose we wanted to use that Cust # info to extract customer info from RCM Customer Master such as the Customer Name ... this is tricky for several reasons. RCM Customer Master Key access is a 6 digit number. IIM Item Master field IDRAW is a 15 alpha position field in which the last 4 digits of our customer number is first 4 positions of this field. See SUB STRING ... we want to extract the first 4 positions SUBSTR(IDRAW,1,4) = EXTRACT_1 See CONCATENATE - we want to join 2 zeros in front of the 4 characters '00' = TWO_0 TWO_0||EXTRACT_1 = COMBINE_2 See FIELD TYPES - Sub String & Concatenation is done on Alpha Character Strings then convert result to numeric digits for getting at RCM except Al does not know how to do that But we can convert the RCM customer number to alpha DIGITS(CCUST) = CUST_ALFA Then Match up CUST_ALFA with COMBINE_2 - - - - - - - - - - - - DATE - also see FIELD TYPES DATE MANIPULATION ... following discussion & examples might be more intelligible if we first review: FIELD TYPES; SUB STRING; CONCATENATION; ECG was Al first effort at figuring out how to make this work. EC_PRICING later effort easier for other folks to follow along. DATE MANIPULATION ... there was a Query/400 discussion in BPCS_L Feb-2000 revealing many nuances that Al was not previously aware of. In the following example we will find which ECL lines have schedule date of "tomorrow." LSDTE is a BPCS numeric field that looks like CCYYMMDD LSDTEA = DIGITS(LSDTE) creating an alpha field from the numeric BPCS field LSDTEAA = SUBSTR(LSDTEA,5,2)||'/'|| SUBSTR(LSDTEA.7,2)||'/'|| SUBSTR(LSDTEA,3,2) This is now an alpha field that looks like MM/DD/YY LSDTED = DATE(LSDTEAA) This is now a true ISO DATE TYPE for IBM DATE MATH even though it has the // alpha embedded characters which is a nuance of capability Al was unaware of until seeing the BPCS_L discussion of Query/400. LSDTEDYS = DAYS(LSDTED) This gives us days since a distant check point for that date. TOMORROW = DAYS(CURRENT(DATE)) + 1 This gives us days equivalent for day after today Selection criteria LSDTEDYS EQ TOMORROW BPCS_L credible lead for more tips like this above may be http://as400service.rochester.ibm.com/ folder \\Tech Info & Databases\Siftware Knowlege Base topic 2.3.4.2 Converting Date for Output to a Display or Printer Help for Define Result Fields Expression field DATE MATH ... query ECG correctly calculates DAYS between two dates after Al had a lot of trouble trying to apply guidance from internet sources. What finally worked for Al was: 1. DA = DIGITS(CCYYMMDD) - this creates ALPHA field from CCYYMMDD numeric one. 2. DT = DATE(SUBSTR(DA,5,2)||'/'|| SUBSTR(DA,7,2)||'/'|| SUBSTR(DA,3,2)) - without the date slashes in MM/DD/YY Query/400 did not accept this as valid 3. Having done this with several date fields DAYS_DIFF = DAYS(DT_NEW) - DAYS(DT_OLD) such that a positive # is days into the future and a negative # is days into the past 4. TODAY = CURRENT(DATE) Today in mm/dd/yy format TOMORROW = CHAR(CURRENT(DATE)) + 1 DAY, ISO) YEAR_AGO = CURRENT(DATE) - 1 YEAR 5. DAYS_AGO = DAYS(TODAY) - DAYS(DT_CHANGE) As in how many days ago this customer order was shipped Last day of = First day of = - month is supposedly (we need to test this) CURRENT(DATE) + 1 MONTH DAY(CURRENT(DATE)) DAY month is supposedly CURRENT(DATE) + 1 DAY DAY(CURRENT(DATE)) DAY DATE MATH ... query CUST_SHIP recognizes that ILDATE is in the format CCYYMMDD so quite easy to directly apply YEAR = YEAR(ILDATE) MONTH = MONTH(ILDATE) and DAY = DAY(ILDATE) to extract correct values. The program appears to work even though we currently only utilize YEAR from this. DATE MATH of ENG930 uses technique MM = DAY(TSDTE)-DAY(TTDTE) in which DAY(input) translates day part so this math is valid only for users who want a 30 day range approximation ... superior approach could be MM(DAY) = DAYS(TSDTE)-DAYS(TTDTE) which converts each input to however many days since Jan 1,0001 then gets difference between the 2 numbers expressed as "DAY" for purposes of any future date math. DATE MATH ball park numbers (YEAR1-YEAR2)*360 + (MM*30) - (DD*-1) lead time days ... see queries ENG920 ENG997 DATE MATH busy work examples - see query ENGSFC* DATE MATH ... ENGCSTDATA is a perfect example of why Al needed to do a query audit on the eve of Y2K. Ditto INVADJS DATE MATH "GOTCHA" was explained in 2001-Aug-20 installment of Club Tech from AS400Network & this "problem" also exists in other areas of IBMath, not just Query/400. A month can contain 28 29 30 or 31 days A year can contain 365 or 366 days Because of this inconsistency, Some operations can generate unexpected results. Example ... start with date 2000-03-31 add one month this gets date 2000-04-30 subtract one month this gets date 2000-03-30 In this example we see that if the math would produce an invalid date, it lowers the value 2000-04-31 to the previous valid date, but there is no "memory" of this "rounding". lets subtract dates to get months rounded down 2000-03-31 to 2000-04-30 is ZERO months because it is seeing that 30 is less than 31 and not recognizing that these are last days of month The math seeks that 2000-03-30 to 2000-04-30 is a month. This pattern will occur if adding or subtracting a number of months, or calculating a duration in months, with a date that is on the 39th 30th or 31st of a month, or instead of months, doing it with years with a Feb 29 date. Date Math Rules of thumb: only works with valid dates; DAY stays the same unless it would be an invalid date, in which case it is lowered to the closest valid date; These changes are not reversable. DATE RE_SEQUENCING ... Hard disk format data is CCYYMMDD Most users want it to print in the format MMDDYY so how to rearrange data? There are several ways DATE RE_SEQUENCED via deconstruct YY field etc then re-assemble using substrings & concatenation tedious example in query SFCEVA3 DATE RE_SEQUENCED in simpler example using some date math controls example in query ECG SHIPSHEET DATE RE_SEQUENCED using date international standard conversions like ISO - - - - - - - - - - - - DEBUG MODE can be used while testing a Query or other program to try to figure out what a problem is ... GO CMDDBG for Debug Commands. This is a complicated topic for which we need to review the Text Books that Al brought back from IBM school to figure out how to do it. DECIPHERING CODES ... there is various documentation floating around, but for people who are familiar with file layouts, sometimes fastest way is a simple DUMP of the data in the file ... example ... Al wanted a logical that excluded ADDITIONAL DESCRIPTION & could not remember the code for regular vs. those lines in the routings / shop operations so RUNQRY *N FOD dumped whole file on-screen with it immediately obvious that "RD" is additional description & "OD" regular lines. Warning ... this dump method dumps raw sequence of data irrespective of logical. DIGIT - also see FIELD TYPES DOCUMENTATION BOGUS ... if you WRKOBJ some field name L* to see a list of all the logicals attached to some file, the access sequence "appears" in the description ... but this can be highly misleading due to BPCS programmers "copying" some other source code & not fixing the documentation reference to reflect the result that they produced. Al prefers to WRKMBRPDM FILE-QDDSSRC LIB-BPCS405CDS POSITION-file then SIX-print reference of the SOURCE code to see which logical access paths are REALLY in what sequence, include what records, etc. - - - - - - - - - - - - EFFICIENCY ... this can be defined a number of ways so let"s be careful. CST270 defines variance as "we launch an order for 500 & we made 100 so far so the variance is 400" ... Al thinks of variance as a count or $ value being incorrect. INPUT OUTPUT report means we scheduled some work but we actually did a different volume, TRADITIONAL Central personnel thought of Efficiency as meaning our standard rate is ... but the reported labor was ... so we express actual as a percentage of standard. However, if some data is reported on one person in a crew then statistics for individual people in the crew could be distorted. EFFICIENCY ... various people might be interested in the data by employee #, work center, facility, operation, item#, customer. EFFICIENCY ... see queries ENGCSTRED ENGEF ENG024 ENGDOWN ENGEMP ENGIND ENGSET = = = = Down Time Total "I" Setup Hours Hours Hours Hours / / / / Costs Costs Costs Costs by by by by Dept / Employee Dept / Employee Dept / Employee Item END ITEM has CUST # last 4 digits in 1st 4 positions of IDRAW but this has not been maintained consistently. - - - - - - - - - - - - END OF REPORT appears by default at the end of each Query/400 report. Some people might not want this to appear ... they might want blanks or some other text. News/400 e-newsletter reported Summer 2000 how to accomplish this. To remove this from ALL query/400 reports, at command line WRKMSGD QRX1905 QQRYMSG select option 2 to change first level text to '' for the message to be updated. Refresh the WRKMSGD screen to verify this. To remove this from ONE query/400 report, follow these steps: Use CRTMSGF Create Message File command to create a message file. Use ADDMSGD Add Message Description to add message ID QRX1905 to the newly created message file, filling first level text with '' (null value) MSG text parameter or whatever value we want to substibute for END OF REPORT. In the CL that runs the query, or on command line if using WRKQRY or RUNQRY there, use OVRMSGF Override with Message File to override message file QQRYMSG with the message file we created. After the query, uuse DLTOVR Delete Override to delete the message file override. EXPRESSION ... you know how we typically put some mathematical relationship in that field? Well we can also use the space to define some purely character string like '__________' for example. Example of this see ENGCSTRED - - - - - - - - - - - - FIELD TYPES - also see DATE MATH FIELD TYPES ... various types of operations can only be done with specific types of fields ... for example we cannot add letters together - just numbers & date math There are special TRUE FALSE fields in other languages Simple addition & subtraction can be done on NUMBERS, DATES & various types of TIME expressions but NOT on ALPHA CHARACTER field types Multiplication & division can only be done on NUMBERS See MATH String manipulation can only be done on ALPHA CHARACTER strings ie. SUBSTRING extraction & CONCATENATION joining and this CAN NOT be done on any other data type One type of field can be converted to another kind of field if the content allows. DATE fields in BPCS are defined numeric because IBM does not allow invalid dates in date fields while BPCS allows stuff there like all zeros or all nines But we need to convert them to IBM Date type to do Date Math and also tell Query to ignore errors due to invalid data there The following examples apply to valid input ... read manual on NULLS Alpha back to numeric - Al has found conflicting internet stories regarding what is doable & then had trouble getting same to work back here at work. BPCS_L credible lead may be http://as400service.rochester.ibm.com/ folder \\Tech Info & Databases\Siftware Knowlege Base search for document # 4892030 for all details in which TIMESTAMP accepts character string as valid time stamp including 6 digit microsecond so 6 digit some other number really be there. Alpha back to numeric - Warning if the contents of alpha field is not valid for numeric then decimal error results INT INTEGER = no such function DECIMAL = no such function Alternative method explained by Bill Robins in BPCS_L consider numeric field CCUSTA created by DIGITS(CCUST) turn it into microseconds portion of a time stamp CCUSTN = MICROSECOND('2000-02-1801.01.01.'||CCUSTA) the number must be a whole number in range 0999999 Alpha Result Alpha Result Today's date Date Result = = = = CHAR(date or time type of field name) DIGITS(numeric field name) CURRENT(DATE) DATE(BPCS data representing a date) DATE could be used against BPCS field containing valid date or the results of date manipulation in alpha format ... warning, some BPCS fields have excessive number of invalid date contents which could distort intended Query Result = DAY(data representing a date) so for example MONTH(19991011) = 11 for Resulting Day extraction Days Result = DAYS(BPCS data representing a date) Days means convert date into # days since Jan 1 0001 for purpose of subtracting two such "dates" to get number of days in between, or adding fixed numbers to this work value Example from News/400 As/400 Network Data Base Forum assuming your JOB's date format is *MDY with "/" separator DAYS(DATE('10/28/99')) - DAYS(DATE('09/28/99')) will return a result of 30 days Tilt ... our data is in format YYYYMMDD our JOB is format MMDDYY Month Result = MONTH(data representing a date) so for example MONTH(19991011) = 10 for Resulting extraction Year Result = YEAR(data representing a date) so for example MONTH(19991011) = 1999 for Resulting extraction Result(specify type) = VALUE(field,pointer) There are others - those we most likely want to use selected here - - - - - - - - - - - - FILE ... 1 query creates a file - 2nd query inputs it see MENU* PFT* STD* FILES ... one HLL (high level langage) creates or populates a file another HLL accesses the data for report / display due to variations between HLL there are some constraints but it can be convenient to use Query to define the layout of a work file that might be read by RPG or some other language however, if you going to change the layout ... Query is one of the FEW languages that lets you do this on the fly ... other languages programs need recompiling to work with new file layout. FILES - layout revision ... when you are changing file layout output of the query needs to REPLACE THE FILE when you are using the same identical file layout output of query can just REPLACE THE MEMBER This is because a member is a MEMBER OF A FILE and the file is the OLD LAYOUT until you replace it. FILES - temporary content ... if you want to populate a file with latest data, run your query against the details, then clear the file of disk space consumption no longer needed, and if you want to avoid accidental collision with other users running same query, put your work file into QTEMP library, whose contents are unique to each individual user sign-on session & go away when sign off. - - - - - - - - - - - - INTERNET FORUMS for HELP with QUERY/400 TIPS See document MOTHERSOS for INTERNET/400 Assistance in general News/400 Home page http://www.news400.com http://www.as400network.com ... upgraded site Forums click on - get to Programming Forums & Communities then locate & get to SQL/400 & Data Base Forum then use the SEARCH ENGINE there for hits on Query/400 INTER RELATIONSHIPS BETWEEN BPCS FILES This is a complex topic which many people need to better understand since misconceptions can lead to invalid queries & invalid programs ... Al now plans to add a section to the bottom of this document further exploring this topic ... in "related topics" section. JOINING FILES ... the Query screen offers 3 kinds of join options whose real meaning is counter-intuitive Re-read UNMATCHED before using them Also check out NLIST in SELECTION criteria Specify Type of Join Type choice, press Enter. Type of join . . . . . . . . 3 1=Matched records 2=Matched records with primary file 3=Unmatched records with primary file Note that in at least one query/400 Al has DELIBERATELY left the kind of join blank, and the query "works" ... just so you know that while the "manual" says there are particular "choices" it is possible to sometimes go "outside the manual" if you think you know what you are doing. JOINING ... Joining files goes up to 32 files in one query Query reads PRIMARY FILE first then links to other files based on fields found in primary file However, if you go purely by the manual, you limited by how many joins you can get on what screens, because not all places offer place to add more lines. JOINING FILES - another GENERAL tip ... IBM Query/400 defaults to file-ids T01 T02 T03 etc. but most BPCS 405 CD files are referred to by a 3 character code "1 letter" for the application such as "F" for shop floor control applications then 2 characters related to unique id within the general area thus if you replace T01 T02 T03 in original definition of file links with FOD FSO FRT or whatever, this can make subsequent references to individual files so much clearer. LAYOUT OF FILES USED IN BPCS sometimes it can be extremely helpful to have a reference list of files critical to BPCS & what fields are in them. RUNQRY XDAY_USAGE gets you a short list of BPCS file names and usage statistics since last OS/400 re-IPL Given name of file, you can DSPFFD IIM *PRINT but Al sometimes finds it more readable to go to the source code for a file & list that ... ask Al for details Al added menu QUERY with reference list of files most people might need to access when creating query/400 definitions. Many UPI manuals have in the back, list of BPCS files relevant to the subject matter of that manual LAYOUT OF QUERY REPORT It is much easier to do a query if you fit it in 132 print bytes than trying to manipulate appearance on second line such as two different numbers lined up good vertically thus it is a big help to F13 see layout sideways so far of F5 the actual data on screen based on Query developed so far LIBRARY LIST REALITIES IN BPCS *LIBL = current library list *FIRST = which format to usually use WRKOBJ AAAL* from another command line to view logicals for file AAA Logicals = pre-select records & sequence efficiency DSPDBR then file name will give you list of all its logicals LIKE - contents of field LIKE the value See SELECTION CRITERIA for examples Opposite is NLIKE - field contents not like the value LIST ... any values in the LIST are acceptable input selection criteria. see queries INVADJITHA ITEM_LIST NLIST is the opposite of LIST - give a list of values to exclude LITERALS ... this concept has rather different interpretations in standard IBM lingo as opposed to how BPCS uses it In IBM lingo, a literal is a string of information treated as TEXT See the Query ENGPICK for an example of a field defined to have the data '________________' so that an underline goes on a report. Also Query ENGRESCH uses literal CHG defined as expression 'Change To' to illuminate data in our data base that needs changing to some other value. LOGICALS ... BPCS comes with a number of access paths to various files that do combinations of things like FRTL03 only accesses the actual operations of routings, not the additional descrip lines You can view what logicals exist via Command line WRKOBJ FRTL* then put 8 in front to see full description. Selecting a logical only tells IBM Query/400 what physical file is relevant ... IBM Query may use a different logical over the same physical based on your definition of what records to use and in what sequence, so do not rely on the logical to do your sorting & selection - always spell that out in your Query. Specifying the most logical logical just helps your query perform more efficiently & an efficient query means more efficient AS/400 for all other users. LOWER CASE ... see CASE - - - - - - - - - - - - MANAGING MASSES OF INPUT TO QUERY Dave Waller had a problem leading to a suggestion to Al Macintyre, that there would be value when running many copies of same query for different parent item #s to keep the query selection screen "open" with last input, so that next input would have less keying needed. Al's response to this may give folks ideas to help with future productivity. First off, there has been a lot of discussion of this very point on several AS/400 internet groups on which Al is active & bottom line is there are several viable solutions for companies whose computer budget is not as much an economy one as Central's is. If you are running a query to SCREEN & the data can be screen printed & is useful to the end users in that format, then F12 when you are done screen printing and you are back at the query selection screen from which you made this selection and it is still "open" for easy make some different selection. If your input selection is very similar to the default stuff in that your final version is a valid picture to be left as the default for other future users of this, then consider WRKQRY 1. Change defaults to one version of what you need. 2. Run the query. 3. Wait until it has finished running with the latest defaults. 4. Repeat steps 1-3 for each of the items that you need this for. Redesign the query so that instead of keying in one item for one report, you key in a whole string of items using the LIST in which you can have a different item on each of an infinity of lines with all AND before lines so you get all inclusion that is the earlier criteria and any of the items included in your LIST. The report wants to have a page break on the parent items used in this way so that you end up with everything you would have got individually only much less hassle process of getting your output. Perhaps the items that you are keying in for your lists came from some other location, and perhaps we should look at where that other location gets its data & write a new query that automates the process ... final query with page breaks on parent item changes, except other location logic determines which items get included overall. - - - - - - - - - - - - MANUALS exist to help us with Query/400 Crowe Chizek class in Query for BPCS at Central had several kinds of hand-outs to us students IBM Query/400 Use - rather large manual & more current version than we have on IBM internet http://www.as400bks.rocheseter.ibm.com where we can download or print selected portions or re-order latest version of any manual News/400 & other trade publications to which MIS subscribes often have Query/400 related articles & examples MIDRANGE dot com has a very active internet discussion list on general 400 topics including Query & searchable archives. Check MOTHER_SOS document for more URLs. MATH ... inside parentheses solved first then left to right + add - subtract / divide * multiply - - - - - - - - - - - - MEMBERS In 400 world, information is stored in various kinds of OBJECTS. In 400 BPCS world, the most common type of Object is a FILE. A 400 FILE has MEMBERS FORMATS LOGICALS RECORDS FIELDS etc. Think of a Table like in a spread sheet. The lines are RECORDS. The columns are FIELDS. The ARRANGEMENT is the FORMAT. A LOGICAL is the ACCESS SEQUENCE for reading RECORDS of a FILE MEMBER. Most programming languages access a whole RECORD at a time. SQL/400 can access an entire column at a time. Some programming languages do not support multiple FORMATS or MEMBERS or LOGICALS. SQL/400 uses what is called a CURSOR which is like a combination FORMAT and LOGICAL. We can have several BUNCHES of information for different purposes Data that someone is working on but it not yet finalized. These different BUNCHES or GROUPS of data are stored in MEMBERS. One MEMBER for each different GROUP or BUNCH. See RMA explanation how member-RETURN in EC* files contains RMA data patterned after Customer Orders How do we find out about such special MEMBERS in BPCS files? On Command Line DSPFD then name of file you interested in then F4 For TYPE use *MBRLIST meaning we want simple list of names of MEMBERs. But most files do not have special MEMBERS How do we find which files do have this scenario without checking all? On Command Line ADDLIBLE XFILES then RUNQRY *N NDAY What you are seeing is a DUMP of DSPFD *MBRLIST type info for all BPCS Notice the data is alphabetical by name of file. F20 sideways past what the file is all about until you get to MEMBER Notice many members are same name as file ... just *FIRST However, we also see LOG RETURN work station names other stuff So now you see we can create a query of file NDAY in library XFILES to only list those files whose count of MEMBERS is more than ONE. File NDAY has that name because it is updated at the end of day If you explore WRKOBJ other files in XFILES library You will find Al has similar stuff at different time stamp to give ability of comparing what got changed in some time frame in terms of volumes of records activity. You can find some of Al"s reports, and clone stuff of your own interest via WRKQRY ... library CIIIQUERY middle line F4 then position list to those starting with X - - - - - - - - - - - - MESSAGE FILES ... see END OF REPORT ... how to change that line default text at end of Query/400. - - - - - - - - - - - - NAMING ... file ID (instead of T01 default) & work fields can be named with more than just letters & numbers legal characters are $ # @ for T01 alternatives underline _ can only be used after 1st character of result fields start with alpha & avoid using a field name from BPCS data base When naming QUERY files & Query itself ... for God sake (a) KNOW naming conventions for BPCS files & software (b) AVOID names that will collide with BPCS files or software (c) Try to group so file name & query name alphabetical proximity logically close to each other ... an example of how NOT to name stuff is what AL found when checking QUERIES so it inspired this advice some co-worker had some query create a work file called FRONT which is unintelligible to AL what on earth that means then FRONT was an input file to query TESTSCRAP which created another work file called NEWMAT (new material). - - - - - - - - - - - - NLIKE - contents of field not LIKE the value See SELECTION CRITERIA for examples Opposite is LIKE - field contents LIKE the value NLIST - give a list of values to exclude opposite criteria is LIST - give a list of valid values See SELECTION CRITERIA NUMBER - also see FIELD TYPES NUMERIC from ALPHA - see FIELD TYPES ON_HAND = opening bal + receipts - issues + adj ON_HAND - allocations = available inventory OVERHEAD computations - see queries LABOR_OV* - - - - - - - - - - - - PARAMETER PASSING ... when one HLL (high level language) program "Calls" another program, it often does so with the criteria of running other program with "parameters" passed down by caller such as do this in a particular facility, for some ranges, and also print on the report what those criteria were. 400 discussion forums claim the same kind of thing can be done with query/400 called from a CL program PRTTXT is a IBM insert to put something on bottom of every page which we used for OS/400 output when most stuff was M/36 but then dropped it when we no longer needed distinguishing but when calling a Query we can change PRTTXT just for that query but if we are doing this on-line we want to blank it out again CHGJOB PRTTXT('Dates:' *CAT &FROMDATE *CAT '-' *CAT &TODATE) this string in a CL program to batch passes parameters of a date range to the Print Text to put on bottom of page. To pass the same criteria to the Query itself, define dates like &QRYFROM *CHAR LEN(10) passing to query with single quotes around 8 digit dates DCL &QUOTE *CHAR LEN(1) VALUE('''') CHGVAR VAR(&QRYFROM) VALUE(&QUOTE *CAT &FROMDATE *CAT &QUOTE) - - - - - - - - - - - - PERCENTAGES - see EFFICIENCY & SCRAP scenarios see queries INVADJ* PRETTY PRINT ... BPCS dates are in the format 1999mmdd but since they are DEFINED NUMERIC, not as dates default edit is 19,99m,mdd ... you can clean that up via F16 edit at the COLUMN SPACING & FORMATING with cursor on the "date" line then 4-word ' - ' some options do not work right due to disparity between IBM definitions & BPCS usage. To get date from 1999mmdd to mmdd1999 either use substring & concatenation or read manual on date formats. - PRETTY PRINT ... Query default for field used to cause total breaks to only print once at beginning of each group if we want field used for control breaks to print on every line, then define a second field for example ITEMX has value ITEM for result select both fields but make ITEMX column width 0 then use ITEMX for control break & ITEM for print PRETTY PRINT ... Query default is totals at all levels But we can put ... at front of break line description With "Y" Yes Suppress Summaries WHAT QUERY IS THIS ... we see queries that do not have a clue. There is no title on top of report telling us what this data is from and there is no NAME for what query it is so that anyone could check it out ... Some people have asked "How can we tell that the data on some report is valid ... where does this data come from?" and Al tells them "If the report is UNATTRIBUTED, that is to say the report has no name & no clarification what the data is about then treat it the same as what you flush down the toilet ... it is probably the work of someone who is still learning query/400 or was learning this stuff at the time that the query was created. COLUMN width on report is dictated by the larger of the two your overall number of sideways characters in header and amount of space needed for largest "edited" value such as minus sign, commas, decimal point, etc. You can run columns together with "0" in front. You can adjust multiple lines via extra large xx number between columns in the overflow, but allow extra time for tinkering with multi-line queries ... this is not a simple art. EDIT "codes" in Query are same as in RPG - ask Al for chart of "appearances" of using different ones impacting floating $ protection, how minuses portrayed, include commas, leading zeros, etc. Most of the stuff you might want can be answered via the "prompt" questions, but since BPCS dates are not "real" dates but numeric, you need to do something like ' - - ' to print '2000-12-31' good & if you want to convert date to 12/31/00 then you need to learn sub-stringing to re-arrange the data. PRINT COMPRESSED tiny font fit more on a line like our schedules Specify width of 198 for the forms, instead of 132 standard in the output type & output form section See WHAT_WENT for example PRINTING - Al highly recommends that a query that might need to be run by folks located in different facilities ... put it on HOLD Otherwise you design it to print one place & along comes another user at another facility & boom it has finished printing some place other than where the end user located. PRINTING TOTALS - See sub-total level break printing - - - - - - - - - - - - PRIORITY - See document "fix tuning" sub topic "Query/400" - Apparently running Query on-line hurts AS/400 model 170 overall system performance for all users much more than it did on AS/400 model 436, except when quick resolution. This can be somewhat eased as illustrated by CIIIQUERY CL Menu Program ORDSCRAPQP PRTTXT ... see PARAMETER PASSING QTEMP ... see FILES RANGE ... any values anywhere from beginning to end of the range work. RANGE from beginning see ENG031 query GT '' (single quote twice) See SELECTION CRITERIA RAW MATERIALS ... once upon a time item #s 910000 thru 920000 BPCS/36 item type 4 evolved in Y2K conversion BPCS 405 planner code 7 - - - - - - - - - - - - RMA (Haz uses MRA meaning same thing) RMA = Return Material Authorization RMA data is stored in a layout that is identical to Customer Orders ECH-header ECL-detail lines ECS-special lines but where customer orders are in ECH-file ECH-member (*FIRST) RMA s in RETURN-member Thus, you could use a standard query listing Customer Order info Copy it changing EC* file member from *FIRST to RETURN and the result is to output same kind of report using RMA data instead of customer order data. You want to change some headers so report is clear this is RMA data. Example of this ... see queries O_IN_USE RMA_USED O_IN_USE lists customer orders with in-use flag = in use RMA_USED lists RMAs with in-use flag = in use How do we find out about such special MEMBERS in BPCS files? See MEMBERS - - - - - - - - - - - - - - - - SCRAP % & PPM ... see queries NEW198 - - - - - - - - SELECTION CRITERIA ... remember that LOGICALS are useful selection criteria to only get active records in some desired sequence so as to make the Query run more efficiently See LIBRARY LIST; LOGICALS Often we create queries that are intended for other users to be making selection criteria choices at run time, such as date range ... in such cases it is smart not to "hide" the stuff the user is to change on a second screen of complex set of criteria but rather put the user-change stuff near top first screen & the more static stuff further down ... if you forget this & want to fix a query ... F9 can insert a line based on where your cursor is at the moment that you do F9. MATH relationships are EQ NE GT LT GE LE RANGE - specify starting & ending LIST - give a list of valid values NLIST - give a list of values to exclude LIKE - contents of field LIKE the value NLIKE - field contents not like the value *LIKE examples '9%' says select all values that start with character "9" ... percent sign is a "filler" '9_0000%' is a selection in which the underline means we do not care what is in 2nd character '%E_A%' means any time find an E followed 2 characters later by an A = select Check manual for if you are looking for one of the characters used to define LIKE IS & ISNOT are for NULLs - see the manual - - - - - - - - - - - - SHIPMENTS before & after invoicing - before & after order line closed Queries with examples of how to do various perspectives include SHIPSHEET SIZING a field Suppose you creating a new query & you can see that some field size is excessive such as x,xxx,xxx,xxx.xxxxx but you not know what is good for your new query ... here is a technique Al Macintyre uses that you might want to copy. 1. In the summary field select MAXIMUM size of population of that field. 2. From main screen do F5 to see the data & "B" on top "position to line" to position it to Bottom of the query report info. 3. Let's suppose the largest price is 200.91 & largest cost is 150.8976 4. Back on column width screen price xxxx.xx & cost xxxx.xxxx Al allows for a field one position larger than current maximum just in case this query selection is not representative of criteria people in the future might use the report. 5. Take maximum back out of summary if not needed for other stuff. 6. User disclaimer warning - this is deciding on basis of current population. We still should consult with people who understand the data application. SSD file in BPCS contains Al figured out during the AMP these fields represent ... Month 01 is the Month 02 is the backwards fields labeled MONTH 01 02 03 ..... 11 12 project (see summer 2000 e-mail) what month of the last EOM month of the previous EOM and so forth SUBSTRING format is SUBSTR(FIELD,START,LENGTH) example START_WHSE SUBSTR(WWHSE,1,1) gets 1st position from warehouse SUBSTRING examples - see query ECG ENGSFC* SUB-TOTAL LEVEL BREAK PRINTING A tip in Dec 2k News/400 Magazine reminds us that level break fields print only on the first line of each grouping, but sometimes we might want a field to be both a level break & print on every line, so they give by example a new field in the "Define result fields" panel that is identical to the one needed for the break & to print, then select both fields to appear, but set the length of one to be zero in the column formatting, so that one does not print, but is selected so it can be used for sorting. - - - - - - - - - - - - SYMBOLS WEIRD on Query reports +++++ implies overflow or divide by zero where the target field cannot handle the data it is getting ... for example percentages where we do not want to see excessive range detailed ... +++++ tells the user the data is just no good Divide by Zero is example of error we can bypass on "Ignore" various kinds of errors +++++ can mean an invalid value for that type of data, such as all zeros or blank in a date field. Run your query interactively in debug mode and look for clues in the job log. SEE DEBUG ***** field length or decimal places inappropriate - - - - - - - - - - - - TESTING NEW QUERY ... RUNQRY name-of-query F4 bottom line *YES While developing a new query, F13 F5 from any screen. TEXT STRINGS ... see LITERALS TIME - also see FIELD TYPES TIPS beyond what is here There is an IBM Manual which Al intends to order extra copies of. There was a "student notebook" distributed to class in Query/400 taught Central personnel by Crowe Chizek in 1998. Query XDAY_USAGE lists our active files & sub-members. Internet users can get to the latest version of most any IBM manual. Internet users can get to various forums of relevant other users. Al subscribes to several technical user newsletters which sometimes contain Query/400 tips. - - - - - - - - - - - - UNMATCHED ... the IBM screen for 3-JOIN is extremely misleading It looks like ... put file-1 in primary, file-2 in secondary, JOIN-3 & expect it will only output file-2 records that do not match file-1, but according to the IBM Query Manual, we use JOIN-3 to see which records in the primary file do not have matching records in the secondary file(s) ... Al Macintyre wrote some queries incorrectly based on interpreting what the IBM screen appeared to say. See query ENG260L by Jerry Cooper Al Mac not know WHY it works, suspects unmatch "really" may be with last "secondary" UNMATCHED ... see BLANK RECORDS. UPPER CASE ... see CASE - - - - - - - - - - - - USER FRIENDLY ... Query CUST_SHIP includes ITEM = ILPROD so that the selection criteria can use a field familiar to everyone. Several queries say YEAR or MONTH for portions of the date. See MATAVAIL which asks for Item equal to 'Enter Part # here' USER IDENTIFIED on Query - Who ran it ... this was discussed in AS/400 Network Forum on Data Base Topics such as SQL & Query/400 and Al tried out the solution - see Query X_QRYALFA from CL INVENGLIST The identification occurs via the CL ... running native Query won't get it. Also it goes on the very bottom of the report so there are issues of alignment & possible over print if query user has also populated bottom. WORK TO BE DONE MEASURE OF IT ... check out concepts Query ENG030 Wires To Cut IPACK times customer order quantity left ZERO LENGTH for a field blocks it from printing, so that we can select fields we want for some math sequence etc. functionality but not have them actually print. See Absolute Values See Sub-Total Level Break Printing ================= =========== R e l a t e d Inter-Relationships between BPCS Files T o p i c s -------------------------------------Al has occasionally encountered cases of query creators & outside programmers (through Crowe Chizek) who evidently lacked an appreciation for the flow of data from BPCS file to BPCS file. This section is intended to SUMMARIZE fundamental linkages. This is not an exhaustive list of files, merely a starting point to try to help clarify some areas of common confusion. Another document goes into detail on what all files are in BPCS 405 CD that are relevant to Central within various application areas ... see QRYDBPNAV8. We have various MASTER or STATIC files that are relatively unchanging other than some running totals & their linkages to other files. AVM FRT IIM MBM RCM Vendor Master Routings Item Master Bill of Materals Customer Master Various other Master files such as valid types & terms Many of these files get updated with summary information at time of closing or completing various kinds of orders Inventory - there tend to be 2 kinds of Inventory files. They might exist for combinations of Item Warehoouse Facility so that depending on what filters a user employs, the answers alter. Inventory Master file basically says what valid combinations exist for warehouses & facilities & so forth & what the rules are for them like which is in which & what is subject to allocations & MRP like in-transit should not be subject to MRP, and crib is not in WIP. Inventory Actual file has info neccessary to see what is now On-Hand at some combination of item / location / facility / whatever and volume of current orders in process that subject that to soon change. When we create an Order, it gets information from relevant master files and whatever user input for the unique nature of current scenario. Most Orders, and a lot of format of two files ... a header or document, and a detail or line file the order or document such as the subsequent history, is stored in the summary file with one record per order or with one record corresponding to each line on invoice. ECH - Header (1 record per) Customer Order ECL - Line each quantity / date / item detail on Cust Order ECS - Specials - like tooling or setup charges EC* - if you look at the "innards" of EC pieces you may notice that QUOTES & RMAs use same layout but unique naming to keep them separated from good orders FSO - Summary (1 record per) Shop Order FOD - Routings data on a shop order from FRT master FMA - Bill of Materials for a shop order from MBM ESH ESL When shipping occurs, data is created in shipping files this data is like a copy of ECH & ECL with shipping specifics from which we can get reprints & corrections Shipping Header Shipping Lines BBH BBL When shipping is completed, data goes into temporary records in a file of that which has not yet been billed Any data in here is finished shipping not yet billed After billing there should be no data in these files Billing Release Header Billing Release Line Items SIH SIL Invoice BB* got Invoice Invoice History contains copies of what was in BBH BBL its info from ES* which got its info from EC* Header - 1 record per Invoice Line - 1 record per line on an invoice SSH Sales History - has information on the $ we invoiced & standard cost SSD Sales History Detail - is like SSH but more detailed ================= =========== R e l a t e d T o p i c s BPCS User Menu CALL a Query via a CL Program -------------------------------------------Several people have asked Al to send them instructions for creating & editing the call programs that make queries so that they can be run directly from a BPCS User Menu. Conceptually this is EASY for Al to do because it is a small subset of editing the larger programs in other programming languages, but for people who have not done this, or much of this, before, it can be a major hurdle to deal with all the nuances. Several Central staff people have done this in the past, but those outside AL MAC who did it most heavily have since left us like JOHN YOUNG & JOE PETERS while others having lapses of long time not doing it like JERRY COOPER & JASON WALLER can lead to forgetting all details exactly how it is done. From most proficient to less so include: AL JASON JERRY The following is NOT intended to be a guide as exactly how to accomplish this, rather it is intended to orient Query experts in what some of the steps are, how to get at more information, and a refresher into the big picture if you not done this in a while. I. Get to WRKMBRPDM Either from Command Line or from Menu OS4 that Al uses heavily. 2. Set the top navigational locations, if they are not already there File QCLSRC Library - CIIIQUERY Then press enter. 3. Note that you can scroll through the list of CL source programs that CALL Query on BPCS User Menus, or "Position to" some familiar valid SSA application prefix like INV ORD SFC or some combination not limited to these 3 character examples. You may notice that some CALL programs have prefixes that violate SSA prefix rules ... they will compile but will not work in BPCS ... they exist because some co-workers have forgotten where you can get away with violating SSA rules & where you cannot. We also have numerous programs whose suffixes are in violation of avoiding conflicts with SSA programs ... these are more dangerous because the query guru might unknowingly name their call program the same as an existing BPCS vanilla program, then place it on a menu for the end user to unknowingly not run the intended query but the original SSA program with unintended consequences. Thus, before anyone creates CALL programs here it is vitally important that we review the NAMING CONVENTIONS. 4. Get to one of the CALL programs that you are familiar with, and you know is working ... there are some here which are not. Many queries reflect some user work-in-process that is not yet finished. 5. Be very careful not to take an option that deletes any. 6. Do F24 a few times to cycle through the many many commands available here then do F23 a few times to cycle through the many option numbers also. 7. Take option to print SIX or view FIVE a familiar program or two. Also do this with ORDBAD, which is refered to later in the orientation. 8. You should notice some common features or formats. Comments or Text that the program does not execute use a particular format of special characters to delineate beginning & ending of the comment text. Traditionally we place a BRIEF text comment at beginning of any program stating what it is that it does, and who wrote it, so that if anyone else wants to change it, you know who to consult with. Any time we make changes to a pre-existing program, we should make a relevant comment. I prefer to "comment out" the old line above the replacement one, so if neccessary it is easy to return to the previous line, & it is easy to back track history of program evolution. Every CL Program starts with a special line delineating start of program and another special line delineating end of program. Blank lines are legal & comments can be anywhere, but when comments are on same line as a command, different rules apply. Most query command lines are in one of the following two format examples. RUNQRY RUNQRY QRY(ENG003) RCDSLT(*YES) QRY(ENG003) RCDSLT(*NO) Both of these examples mean ... run the Query ENG003. RCDSLT(*YES) means give user a pop-up menu to change selection criteria. RCDSLT(*NO) means run the query as-is with no pop-up choices. SBMJOB in front means send the whole thing to JOBQ. When Al figures out how to make this work, will update here. The EASIEST way to create a new query involves copying an existing query and keying over the text lines with the relevant name of your query, what the RCDSLT value needs to be, & adjust comment on top appropriately. If you want to add some fancy features, you need to know a bit more about navigating PDM & SEU, both of which have some manuals, but lots of on-line help, which is heavily nested, and is mentioned piecemeal in this orientation to try to avoid overwhelming you. 9. Now find a Query CL program that only you use, or copy a good one to a temporary work name that is not already some other source. We are going to be doing some simple editing of it to illustrate a few of the things that can be done beyone the above basics. For the program that you will be messing with, take option TWO to edit it. On the top line key "B" & enter to get to the "Bottom" of the program. Incidentally, You can stick cursor on that top command line & F1 help there to get info on the many specialized things that can be keyed on the command line. Depending on whether you are in Edit Mode or View Mode, your options will vary. 10. Now that you are at the bottom, seeing lots of the program, take F15 and you will see a screen that looks something like this. Browse/Copy Options Type choices, press Enter. Selection . . . . . . . . . . . 1 Copy all records . . . Browse/copy member . . File . . . . . . . . Library . . . . . . Browse/copy spool file Job . . . . . . . . . User . . . . . . . Job number . . . . Spool number . . . . Display output queue . Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N ORDBAD QCLSRC CIIIQUERY QRYTECHNIQ QRYTECHNIQ AL *LAST *LAST QPRINT *LIBL 1=Member 2=Spool file 3=Output queue Y=Yes, N=No Name, F4 for list Name, F4 for list Name, *CURLIB, *LIBL Name, F4 for list Name Name, F4 for list Number, *LAST Number, *LAST, *ONLY Name, *ALL Name, *CURLIB, *LIBL Make sure the Top line is "1" select Member and the next 4 lines are as I have illustrated Copy all records . Browse/copy member File . . . . . . Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . N ORDBAD QCLSRC CIIIQUERY Y=Yes, N=No Name, F4 for list Name, F4 for list Name, *CURLIB, *LIBL Change yours to agree with my example. Then press enter. You should now have a split screen with your original program on top, and access to ORDBAD on the bottom. 11. Move your cursor into the bottom section & scroll. Find one of the lines that starts OVRPFTF Notice the digits at far left ... stick letter C over them in front of a line that starts OVRPRTF If your OVRPRTF code "line" actually runs to several lines, then instead stick CC over first one & CC over last one. Now move cursor so that it is in the top section & scroll. Find the line that starts RUNQRY ... stick letter B over the digits at far left of the line that has RUNQRY Now press ENTER. You see what happened? The "C" said "COPY" this line. The "B" said "insert it here "Before" this line. "CC" means copy a block of lines, in which you mark first & last lines. Incidentally, You can stick cursor over the digits portion & F1 help there to get info on the many specialized things that can be keyed at the side. Depending on whether you are in Edit Mode or View Mode, your options will vary. I hope you now see how this is not something that is simple to write instructions to someone how to edit a CALL Query Program. This is a very powerful infrastructure, but how much of this stuff does a person need to know? Do F12 to get rid of the bottom stuff. 12. Let's do a summary review of the OVRPRTF line. OVRPRTF FILE(QPQUPRFIL) SAVE(*YES) USRDTA('O_BAD_ECH') If you have worked a lot with queries, I am sure you are aware that they end up on spool with the "file name" QPQUPRFIL which can be difficult to figure out which is which when we have a large number of them. 13. Assuming your security lets you do this, run ORDBAD to see what Al is doing with this string of queries listing suspicious circumstances in the customer order files. ORDBAD is on the SYSC menu ... do not run anything else from there, just this query string that precedes the special reorgs, Then WRKSPLF & see how these queries ended up with unique identification in the User Data column clarifying which is which. SAVE(*YES) means that after printing, leave a copy on spool for reprint capability, similar to how we do our schedules. 14. Let's look at OVRPRTF other options in more detail. OVR PRT F means Over Ride the Printer File defaults which in this case means the Query was written in a certain way and this CL is over-riding some defaults that the Query creator does not have access to. We can also over-ride defaults that the Query writer does have access to. Any time a 400 program is over-writing something, the over-write has to come before that which is being over-ruled. OVRPRTF FILE(QPQUPRFIL) SAVE(*YES) USRDTA('O_BAD_ECH') Move cursor to the line that has the OVRPRTF and do F4. Scroll through & compare to the above line which you should have printed out from earlier instructions. It should soon be evident that there is an enormous amount of stuff which can be over-ridden at time of Query execution, when it is a printed report. To satisfy curiosity, you can on any line place the cursor and do an F1 help or F4 list of all available options. You might also like to do the same F4 exploration on the RUNQRY line. However, you see the incredible detail possible in only one command line. 15. The next time you are in Al office, ask Al to show you where the CL Reference Manuals are - aggregate about 10 inches thick. The one that is in a binder is the one Al uses most often. Not all of these commands are appropriate to be using with a RUNQRY. In the CL manual in the binder, the chapter that Al uses most heavily and this is for far more than CALL program to RUNQRY, Al uses Chapter 2 more heavily than all other chapters combined, in the whole 10 inches of all the CL manuals. It has nice review sections of the types of commands available, the steps involved in passing a variable, conditional branching, nested IF DO & other structured functions, the mechanism of retrieving IBM values, and lots more not needed for RUNQRY. You might want to photocopy a few of its pages for reference. 16. Al has stated on several occasions that the most common errors when someone tries to run a BPCS Menu CL program to CALL a query are: a) The user is signed on as someone who is not authorized to run it. b) There is an error message in what Al thinks is plain sight, with massive second level help assistance, but the end user instead says that the call failed & they have no idea why. c) The person who created the query or call made some error. d) A member of our committee of query manipulators managed to delete a query that someone else uses. Many of these issues are addressed elsewhere in Al"s write-ups, but how do you check on the possibility that something is missing, that may have existed in the past. that is an essential ingredient in making it posssible for query to run, or alternatively making sure that all the pieces are in place? 17. This is a question Al plans to pursue on the internet, when Al time permits. A related issue is if someone wants to replace a query how do we get from Query Definition Name to list of CL program(s) using it that need substitution or revision? Also when we find out that some field is not a good idea like IIM ISCST so queries using it ought to be re-thought ... how get list of queries using that field? Get to a command line & GO CMDREF Take the option to display program references. The program is the CL program to CALL the query. Leave *LIBL Library list alone. Select *PRINT and *ALL types of info available. Unfortunately QUERY is not recognized by this tool. WRKOBJ using some prefix of query we been working with like ENG* & F4 select type *QRYDFN only - then 8 scroll dates in there created originally / changed since / saved last / restored did the 436-170 restore wipe "used" or did same day change do it? Al would like to generate a list of queries no one used in X weeks X months etc. ... candidates for older versions. Managing our mass of Queries in an Intelligent fashion -----------------------------------------------------Often we can be faced with what seems like an insurmountable task getting a handle on what is out there, and it continues to grow. Look at ENG menu collection of experimental Query file access. INVENGLIST = a list of all of our queries in sequence by alpha description INVENGVIEW = inquiry format list all our queries thanks to this perspective, some query creators have been adjusting their descriptive text to improve appearance here INVENGQRY = RUNQRY from menu, assuming you know name of query in which INVENGVIEW is a big help to that end Look at MPS+ nitely menu options for XDSPGMETC - this replaces / updates the latest list of queries XDSPOBJPGM - this is the actual job that runs via JOBQ to replace query list they use standard live BPCS library list combined with BTESTSRC XFILES & CHGORDHST2 But sometimes there is a desire to get a reference list of what files are used by which queries ... input & output. MIDRANGE_L & various forums (see document MOTHER_SOS) have had lots of discussion of this & related topics. DMPOBJ of the *QRYDFN then copy its spool file to a physical file then process that with an RPG program which uses the QDT from QQQQRY API as a guide ... this does not work out very well if you have a large number of queries to process ... 100 is really too large for this approach. www.as400network.com (We are members thanks to News/400 subscription) search for article by Gary Guthrie in News/400 March 1997 page 117 entitled "Determining Query Specifications" which describes an MI program to retrieve query file information. ================= =========== R e l a t e d T o p i c s