Skip to Content
author's profile photo Former Member
Former Member

need the logic behind this program

hi,

i was going through the sap 4.7e help files. In the loops section i found this sample program.

DATA: BEGIN OF TEXT,

WORD1(4) VALUE 'This',

WORD2(4) VALUE 'is',

WORD3(4) VALUE 'a',

WORD4(4) VALUE 'loop',

END OF TEXT.

DATA: STRING1(4), STRING2(4).

DO 4 TIMES VARYING STRING1 FROM TEXT-WORD1 NEXT TEXT-WORD2.

WRITE STRING1.

IF STRING1 = 'is'.

STRING1 = 'was'.

ENDIF.

ENDDO.

SKIP.

DO 2 TIMES VARYING STRING1 FROM TEXT-WORD1 NEXT TEXT-WORD3

VARYING STRING2 FROM TEXT-WORD2 NEXT TEXT-WORD4.

WRITE: STRING1, STRING2.

ENDDO.

The output is:

This is a loop

This was a loop

i need to know how this "is" is replaced by "was".

in the help file he told that it will be replaced but did not mention how and why.

I will quote his words about this condition

"The structure TEXT represents a series of four equidistant fields in memory. Each time the first DO loop is processed, its components are assigned one by one to STRING1. Whenever STRING1 contains ‘is’, its contents are changed to ‘was’. <b><b>This also changes TEXT-WORD2 to ‘was’.</b></b> Each time the second DO loop is processed, the components of TEXT are passed to STRING1 and to STRING2."

i wanna know why this text-word2 is changing from "is" to "was".

regards,

maqsood

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Nov 25, 2005 at 03:55 AM

    Well the first time, word2 is 'is' and is written and then changed to 'was'. The second DO writes what is there 'was'.

    If you put in a break-point in the DO/ENDDO, you can see what's happening.

    (The first one.)

    Rob

    Message was edited by: Rob Burbank

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Maqsood,

      i have inseterd wan small code inside yur report, just run it to understand in which iteration number "is" becmes "was".

      plz reward point if it helps you..

      just run this code:

      REPORT zanid_test4 MESSAGE-ID zz.

      *

      DATA: BEGIN OF TEXT,

      WORD1(4) VALUE 'This',

      WORD2(4) VALUE 'is',

      WORD3(4) VALUE 'a',

      WORD4(4) VALUE 'loop',

      END OF TEXT.

      *----the new porton of code

      data: loopno like sy-index.

      *----


      DATA: STRING1(4), STRING2(4).

      DO 4 TIMES VARYING STRING1 FROM TEXT-WORD1 NEXT TEXT-WORD2.

      WRITE STRING1.

      IF STRING1 = 'is'.

      *----the new porton of code

      loopno = sy-index.

      call function 'POPUP_TO_INFORM'

      exporting

      titel = 'Debuging'

      txt1 = 'Iteration Number is where [is] becomes [was]'

      txt2 = loopno

      txt3 = 'Hit Enter to Continue'.

      *----the new porton of code

      STRING1 = 'was'.

      ENDIF.

      ENDDO.

      SKIP.

      DO 2 TIMES VARYING STRING1 FROM TEXT-WORD1 NEXT TEXT-WORD3

      VARYING STRING2 FROM TEXT-WORD2 NEXT TEXT-WORD4.

      WRITE: STRING1, STRING2.

      ENDDO.

  • author's profile photo Former Member
    Former Member
    Posted on Nov 25, 2005 at 04:32 AM

    Hi Maqsood,

    Concept of REPEAT STRUCTURE.

    1. wanna know why this text-word2 is changing from "is" to "was".

    The keyword VARYING

    introduced the concept of repeat structure.

    2. In a table, if there are

    continuous patterns of fields

    we can ITERATE thru them

    (without each field name)

    3. Hence test-word2 changes.

    4. Concept of repeat strcuture is applicable

    to many tables like PA0008.

    Hope the above helps.

    Regards,

    Amit M.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 25, 2005 at 06:16 AM

    Hi again,

    Sorry for the previous reply

    which was not at all answering your question.

    (actually i did not understand fully your query)

    (transfer type: pass by value and result).

    1. I tried the code at my end. I also checked the

    documentation for VARYING.

    2. Just as the 3rd iteration begins, the field changes.

    3. If u see the documentation of VARYING,

    It is SPECIFIED THAT

    If the value of f changes during the loop pass, the new value is then placed in the appropriate field fn assigned to f (<b>transfer type: pass by value and result</b>). If the loop pass terminates because of a dialog message, the new

    value is not passed back if f changes.

    4. Hence, this is the nature of ABAP language w.r.t VARYING.

    Hope it helps.

    Regards,

    Amit M.

    Message was edited by: Amit Mittal

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.