AS/400 subfiles

620 pts.
Tags:
AS/400
AS/400 Subfiles
It's a general question. I need to update and delete the records in file at a time using subfile screens. Please see the below subfile screen when I'm selecting alternative option and press enter, it's not working. Please advise. Program logic:
0025.00 C     SFLPROCESS    BEGSR

0026.00 C                   READC     SFLREC

0027.00 C                   SELECT

0028.00 C                   WHEN      A_OPT='2'

0028.02 C                   DOU       %EOF

0028.03 C     A_EID         CHAIN     EMPR

0028.04 C                   IF        %FOUND()

0028.05 C                   EVAL      EID=A_EID

0028.06 C                   EVAL      ENAME=A_ENAME

0028.07 C                   EVAL      ESAL=A_ESAL

0028.08 C                   EVAL      EADDRESS=A_EADDRESS

0033.00 C                   UPDATE    EMPR

0033.01 C                   ENDIF

0033.02 C                   READC     SFLREC

0033.03 C                   ENDDO

0034.00 C                   WHEN      A_OPT='4'

0034.02 C                   DOU       %EOF

0034.03 C     A_EID         CHAIN     EMP

0035.00 C                   IF        %FOUND()

0036.00 C                   DELETE    EMPR

0037.00 C                   ENDIF

0037.01 C                   READC     SFLREC

0037.02 C                   ENDDO

0039.00 C                   ENDSL

0039.01 C                   ENDSR
And here's the subfile screen:
2=UPDATE  4=DELETE                   
                                                             
                                                             
    OPT     EID       ENMAE         ESAL            EADDRESS 
                                                             
     2         4    RAVIKUMAR         34000    BANGLORE      
     4         5    CHOWDARY          45000    VIZAG         
     2         7    SWETHA            45000    HYDERABAD     
     4         8    ROJA1             78000    NAGPUR
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • philpl1jb

    My advise is:

    it's time for you to learn how to use the debugger

    Assuming that you're working from the green screen command prompt.

    STRDBG <F4>

    Enter your program name

    Change: Update production files . . . .  *YES

    Use <F6> to mark points in your code where you want the program to pause

    Press <F3> and then invoke your program.

    <F11> will show you the values in any variable

    <F10> will step through the code from the stop

    Now you can solve more of your own problems.




    54,090 pointsBadges:
    report
  • chowas400
    Hi Philp,

      Thank you for your response..

    I know the debug process ... anyway i got the exact output when i'm using if cond instead of select when cond for the above code. but
    Is it possible select when cond for the above code.?

    Thanks again..
    620 pointsBadges:
    report
  • chowas400
    Hi Philp,

    Now i got the exact output, when i'm using select when condition too..
    Now i'm using debug method efficiently ..

    Thank you so much..
    620 pointsBadges:
    report
  • philpl1jb

    Yes, but your code is convoluted.

    It looks something like this:

    0026.00 C                   READC     SFLREC
    0027.00 C                   SELECT
    0028.00 C                   WHEN      A_OPT='2'

                  Dou %EOF
                            do stuff that's for a 2 response
               ReadC
           Enddo
    0034.00 C                   WHEN      A_OPT='4'
           Dou EOF                  
                            do stuff that's for a 2 response
    0037.01 C                     READC     SFLREC   readC will only be done after a 4 type response
           Enddo
    0037.02 C                   ENDDO
    0039.00 C                   ENDSL


    You use the select structure after the first subfile read but if that record has a 2 you then loop through all the other subfile active records doing "2" stuff.  Or if the first Readc brings a "4" then you get locked into the "4" stuff



    54,090 pointsBadges:
    report
  • philpl1jb

    So untangling your code produces this

    0025.00 C     SFLPROCESS    BEGSR

    0026.00 C                   READC     SFLREC
    0028.02 C                   DOU       %EOF
                                       EXSR      ProcOneReq
    0037.01 C                   READC     SFLREC
    0037.02 C                   ENDDO
    0039.01 C                   ENDSR

    0025.00 C     ProcOneReq    BEGSR
    0027.00 C                   SELECT

    0028.00 C                   WHEN      A_OPT='2'
    0028.03 C     A_EID         CHAIN     EMPR
    0028.04 C                   IF        %FOUND(EMP)
    0028.05 C                   EVAL      EID=A_EID
    0028.06 C                   EVAL      ENAME=A_ENAME
    0028.07 C                   EVAL      ESAL=A_ESAL
    0028.08 C                   EVAL      EADDRESS=A_EADDRESS
    0033.00 C                   UPDATE    EMPR
    0033.01 C                   ENDIF

    0034.00 C                   WHEN      A_OPT='4'
    0034.03 C     A_EID         CHAIN     EMP
    0035.00 C                   IF        %FOUND(EMP)
    0036.00 C                   DELETE    EMPR
    0037.00 C                   ENDIF

    0039.01 C                   ENDSR

    Note: It's a good practice to use the record names in the %EOF functions for actual files .. code gets changed over time, without the file name in the %EOF it will actually refer to the most recent read of any file or subfile (even if it's in a different subroutine). That's an error waiting to happen.

    54,090 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: