ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

how to substring a character field in cobol

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

  • how to substring a character field in cobol

    Hi,

    I have a character field of length 2000.
    Here I got data from a dtaara like:

    '1111111111111111111111111111111111110000001111'

    Now, I have to check whether in possition 79 we have a '0' or '1'.

    I am new to COBOL but I tried using Unstring in cobol but it was unsuccessful.

    Please help me out in getting the code right, so that I can get '0' or '1' in a Work field from the string above.

  • #2
    Re: how to substring a character field in cobol

    No need to use UNSTRING or whatever. Use Accept instead :

    Code:
    SPECIAL-NAMES.                                 
         DATA-AREA is MyDA.      
    
    WORKING-STORAGE SECTION.
    01  MyFld pix x.                                     
                         
                                                   
    PROCEDURE DIVISION.                            
    A00.                                         
        Accept MyFld From MyDA For "[I]My Data Area Name[/I]" At 79 
        End-Accept.
        Display MyFld.
    Last edited by Mercury; March 18, 2011, 08:05 AM.
    Philippe

    Comment


    • #3
      Re: how to substring a character field in cobol

      You french devil is there nothing you dont know
      All my answers were extracted from the "Big Dummy's Guide to the As400"
      and I take no responsibility for any of them.

      www.code400.com

      Comment


      • #4
        Re: how to substring a character field in cobol

        LOL ! It reminds me of Socrates famous quote, "All that I know is I know nothing".

        You know my pal, I just learnt how to read the technical books I provided me with plus some practise of the language on mainframes & i.
        Philippe

        Comment


        • #5
          Re: how to substring a character field in cobol

          Philippe -- have a fantastic weekend....
          All my answers were extracted from the "Big Dummy's Guide to the As400"
          and I take no responsibility for any of them.

          www.code400.com

          Comment


          • #6
            Re: how to substring a character field in cobol

            Thanks Jamie, same to you.
            Philippe

            Comment


            • #7
              Re: how to substring a character field in cobol

              I knowthis is already been answered.
              But an alternative way would be to use reference modification (P:L) p = position, l=length
              Example
              If My Data Area Name(79:1) = "1"
              Then do this
              Else do somthing else
              End-If.

              Just my 2 cents.
              JM
              John M. Mauro
              Software Engineer
              nThrive

              Comment


              • #8
                Re: how to substring a character field in cobol

                Thanks John..
                All my answers were extracted from the "Big Dummy's Guide to the As400"
                and I take no responsibility for any of them.

                www.code400.com

                Comment

                Working...
                X