ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Check if user left the field blank

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Check if user left the field blank

    Hi,

    I am just trying one simple example to show the field in reverse image if user left the field blank. but the check "= SPACE" is not working. could someone please guide. Control is not going inside IF condition. I am just pressing Enter without filling any field. in the following code I checked if my first field ISBN is filled or not.

    Code:
           IDENTIFICATION DIVISION.                       
           PROGRAM-ID. ADDBOOKCB.                         
    
           ENVIRONMENT DIVISION.                          
           INPUT-OUTPUT SECTION.                          
           FILE-CONTROL.                                  
    
               SELECT BOOK-DSP ASSIGN TO WORKSTATION-BOOKD
               ORGANIZATION IS TRANSACTION                
               ACCESS MODE IS SEQUENTIAL.                 
    
           DATA DIVISION.                                 
           FILE SECTION.                                  
               SELECT BOOK-DSP ASSIGN TO WORKSTATION-BOOKD
               ORGANIZATION IS TRANSACTION                
               ACCESS MODE IS SEQUENTIAL.                 
    
           DATA DIVISION.                                 
           FILE SECTION.                                  
           FD  BOOK-DSP                                  
               LABEL RECORDS ARE STANDARD.               
           01  BOOKDSP-RECORD.                           
               COPY DDS-ALL-FORMATS OF BOOKD.            
    
           WORKING-STORAGE SECTION.                      
           77  ALL-FILLED          PIC X.                
           PROCEDURE DIVISION.                           
               OPEN I-O BOOK-DSP.                        
               WRITE BOOKDSP-RECORD FORMAT IS "CRTBOOK". 
               READ  BOOK-DSP RECORD.                    
               PERFORM VALIDATION UNTIL ALL-FILLED = "Y".
    
           VALIDATION.                                   
               MOVE "Y" TO ALL-FILLED.                   
               IF ISBN OF CRTBOOK-I = SPACE    THEN       
                  MOVE "1" TO IN99 OF CRTBOOK-O         
                  MOVE "N" TO ALL-FILLED                
               END-IF.                                  
    
               WRITE BOOKDSP-RECORD FORMAT IS "CRTBOOK".
               READ  BOOK-DSP RECORD.                   
               STOP RUN.

  • #2
    Doesn't the READ need FORMAT IS "CRTBOOK"? I don't know if that's the cause of your problem or not, but it looks funny to me.

    Comment


    • #3
      it seems initially all the screen fields are filled with some garbage. I filled the screen fields with SPACE before processing. working fine now.

      Code:
                 MOVE SPACE TO CRTBOOK-I.                  
                 MOVE SPACE TO CRTBOOK-O.                  
      
                 WRITE BOOKDSP-RECORD FORMAT IS "CRTBOOK". 
                 READ  BOOK-DSP RECORD FORMAT IS "CRTBOOK".

      Comment


      • #4
        Since you defined the screens in the FILE SECTION, they overlay each other in memory. This can cause all sorts of invalid-data problems.

        I have had better success by defining the screens in WORKING-STORAGE, where I can separate them.

        For example, if a display file has two formats, SCREEN1 and SCREEN2, I would define them this way:

        Code:
        FILE-CONTROL.
            SELECT DISPLAY-FILE     ASSIGN TO WORKSTATION-MYDSPF
            etc.
        
        DATA DIVISION.                     
        FILE SECTION.                      
        FD  DISPLAY-FILE.                  
        01  DISPLAY-RECORD     PIC X(1920).
        
        WORKING-STORAGE SECTION.                                    
        01  SCREEN1-IN.             COPY DDS-SCREEN1-I OF MYDSPF.
        01  SCREEN1-OUT.            COPY DDS-SCREEN1-O OF MYDSPF.
        01  SCREEN2-IN.             COPY DDS-SCREEN2-I OF MYDSPF.
        01  SCREEN2-OUT.            COPY DDS-SCREEN2-O OF MYDSPF.
        You'll have to use WRITE ... FROM ... and READ ... INTO ..., of course.

        After a READ, use MOVE CORR to copy the input buffer to the output buffer. Work from the output buffer from that point on, except for input-only fields.

        Credit for this approach goes to Barry Arnold, a programmer I used to work with.

        Comment


        • #5
          Originally posted by kishor View Post
          it seems initially all the screen fields are filled with some garbage.
          That's not unusual in programming languages. Before using a variable, it should be initialized to some known value, e.g., set it to blanks right at the start. Otherwise it will hold whatever was previously in those memory locations.
          Tom

          There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

          Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

          Comment


          • #6
            Code:
            0030.00
            0031.00 working-storage section.
            0032.00 01 ws-file-status.
            0033.00 05 ws-cus-file-status pic x(2) value '00'.
            0034.00 05 ws-cus-screen-file-status pic x(2) value '00'.
            0034.01
            0035.00 01 ws-screen-control-area.
            0036.00 05 ws-key-pressed pic x(2).
            0039.00 88 function-key03 value "03".
            0039.04
            0040.00 01 ws-screen-indicators.
            0041.00 05 ws-scr-indicator pic 1 occurs 99 times indicator 1.
            0042.00 88 indicator-off value b"0".
            0043.00 88 indicator-on value b"1".
            0043.01
            0044.00 01 ws-indicators-used.
            0045.00 05 invalid-cusno pic 9(2) value 21.
            0045.01
            0047.00 01 ws10-abend-variables.
            0048.00 05 ws10-program-name pic x(9) value 'cusminqy'.
            0049.00 05 ws10-file-status pic x(2) value spaces.
            0050.00 05 ws10-error-message pic x(80) value spaces.
            0050.01
            0050.02 01 work-fields.
            0050.03 05 ws-check pic x(1) value 'n'.
            0050.05
            0051.00 procedure division.
            0052.00 0000-start.
            0053.00 perform 1000-initialisation.
            0054.00 perform 2000-main-processing
            0055.00 until function-key03.
            0056.00 perform 3000-termination-process.
            0057.00 0000-exit.
            0058.00 stop run.
            0059.00 *-------------------------------------*
            0060.00 1000-initialisation.
            0061.00 perform 1100-open-file.
            0062.00 initialize ws-screen-indicators.
            0063.00 initialize ws-key-pressed.
            0064.00 initialize cuspmt-i.
            0065.00 perform 1200-display-header.
            0066.00 *-------------------------------------------------------------*
            0067.00 * this section will be used to open the files *
            0068.00 * used in this program. *
            0069.00 *-------------------------------------------------------------*
            0070.00 1100-open-file.
            0071.00 open input customer-file.
            0072.00 evaluate ws-cus-file-status
            0073.00 when '00'
            0074.00 continue
            0075.00 when other
            0076.00 move ws-cus-file-status to ws10-file-status
            0077.00 move 'error in opening cus file' to ws10-error-message
            0078.00 perform z200-file-abend-process
            0079.00 end-evaluate.
            0080.00
            0081.00 open i-o customer-screen-file.
            0082.00 evaluate ws-cus-screen-file-status
            0083.00 when '00'
            0084.00 continue
            0085.00 when other
            0086.00 move ws-cus-screen-file-status to ws10-file-status
            0087.00 move 'error in opening cus screen file'
            0088.00 to ws10-error-message
            0089.00 perform z200-file-abend-process
            0090.00 end-evaluate.
            0091.00 *--------------------------------------------------------*
            0092.00 * this section will display the employee add screen *
            0093.00 *--------------------------------------------------------*
            0094.00 1200-display-header.
            0095.00 write display-record
            0096.00 format is "cuspmt"
            0097.00 indicators are ws-screen-indicators.
            0098.00 read customer-screen-file
            0098.01 format is "cuspmt"
            0099.00 indicators are ws-screen-indicators.
            0100.00 *--------------------------------------------------------*
            0101.00 * display the emp screen unti f03 key is pressed *
            0102.00 *--------------------------------------------------------*
            0103.00 2000-main-processing.
            0103.01 move cust of cuspmt-i to cust of cusmst.
            0103.02 read customer-file
            0103.03 invalid key
            0103.04 set indicator-on(invalid-cusno) to true
            0103.05 perform 2200-display-header
            0103.13 not invalid key
            0103.14 move 'y' to ws-check
            0103.15 perform 2100-write-screen-record
            0103.21 end-read.
            0120.00 ************************************************** *********
            0121.00 *---------------------------------------------------------*
            0122.00 * this will check the emp no is blank and also *
            0123.00 * if the record already present in data base *
            0124.00 *---------------------------------------------------------*
            0124.01 2100-write-screen-record.
            0124.03 move name of cusmst to name of cusflds-o.
            0124.04 move city of cusmst to city of cusflds-o.
            0124.05 move state of cusmst to state of cusflds-o.
            0124.06 move addr of cusmst to addr of cusflds-o.
            0124.07 move cust of cusmst to cust of cusflds-o.
            0124.08 write display-record
            0124.09 format is "cusflds"
            0124.10 indicators are ws-screen-indicators.
            0124.11 read customer-screen-file.
            0135.00 *--------------------------------------------------------*
            0135.01 2200-display-header.
            0135.02 initialize cuspmt-i.
            0135.04 write display-record
            0135.05 format is "cuspmt"
            0135.06 indicators are ws-screen-indicators.
            0135.07 read customer-screen-file
            0135.08 format is "cuspmt".
            0136.00 z200-file-abend-process.
            0137.00 display 'program name :' ws10-program-name.
            0138.00 display 'file status :' ws10-file-status.
            0139.00 display 'error message :' ws10-error-message.
            0140.00 3000-termination-process.
            0141.00 close customer-file.
            0142.00 close customer-screen-file.
            ​

            Comment

            Working...
            X