Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

step loop

Former Member
0 Kudos
334

Hi experts,

I have a small problem in step loops in my program. I am displaying 2 rows in my step-loop. My requirement is that I want initially the fields will be blank. After pressing 'NEXT', the first row will display the first value, but the next row will be blank. On pressing 'NEXT' again, the next subsequent value will be displayed in the blank row. Then all the values will get populated one by one. In this program, I have hardcoded the values for testing purposes and populated in the internal table. However, this is not the actual approach as in the real time the fields will be populated dynamically as per the user. Below are the screenshots of my code and the output.

1) I declared the following variables:

TYPES : BEGIN OF TY_NUMBER,
              NUMBER01 TYPE CHAR10 ,
             END OF TY_NUMBER.

DATA : IT_NUMBER TYPE STANDARD TABLE OF TY_NUMBER ,
       WA_NUMBER  LIKE LINE OF IT_NUMBER,
       FILL TYPE I,
       G_OK_CODE TYPE SY-UCOMM.

DATAOK_CODE TYPE SY-UCOMM,
       SAVE_OK TYPE SY-UCOMM.

DATA: IDX   TYPE I,
      LINE  TYPE I,
      LINES TYPE CHAR10,
      LIMIT TYPE I,
      C     TYPE I.

2) I created the layout as shown:

   

3) The following is the flow logic layout.

  

4) IN MODULE TRANSP_ITAB_OUT: I wrote this

IDX = SY-STEPL + LINE.
READ TABLE IT_NUMBER INTO WA_NUMBER INDEX IDX.
  IF IDX = 1.
    EXIT.
    ENDIF.

5) in MODULE TRANSP_ITAB_IN I wrote:

LINES = SY-LOOPC.
  IDX = SY-STEPL + LINE .
  MODIFY IT_NUMBER FROM WA_NUMBER INDEX IDX.

6) IN MODULE USER_COMMAND_0100, code is:

CASE SY-UCOMM.


    WHEN 'NEXT'.
        WA_NUMBER-NUMBER01 = '12344'.
      INSERT WA_NUMBER INTO TABLE IT_NUMBER.
      WA_NUMBER-NUMBER01 = '12345'.
      INSERT WA_NUMBER INTO TABLE IT_NUMBER.
      WA_NUMBER-NUMBER01 = '12346'.
      INSERT WA_NUMBER INTO TABLE IT_NUMBER.
      WA_NUMBER-NUMBER01 = '12347'.
      INSERT WA_NUMBER INTO TABLE IT_NUMBER.
      WA_NUMBER-NUMBER01 = '12348'.
      INSERT WA_NUMBER INTO TABLE IT_NUMBER.
      WA_NUMBER-NUMBER01 = '12349'.
      INSERT WA_NUMBER INTO TABLE IT_NUMBER.
      DESCRIBE TABLE IT_NUMBER LINES FILL.
      LINE = LINE + 1.

CALL SCREEN 100.

WHEN 'BACK'.
  LEAVE TO SCREEN 0.
    ENDCASE.

7) This is the output I am getting in the initial screen.

😎 On pressing 'NEXT', I am getting the following:

9) But I want the output as below after the initial screen:

Hence there should be a  blank row just after the first record is shown in the first field. After that all the records should be populated one after the other without any blanks in between.

Regards.

Souvik.

1 ACCEPTED SOLUTION

nabheetscn
SAP Champion
SAP Champion
0 Kudos
295

Souvik

First of when your screen is called PBO will be called and at that time your internal table is empty so its displaying blank records. When you press next then you are filling the data. What you should do is in PBO check if IT_NUMBER is initial then

     WA_NUMBER-NUMBER01 = '12344'.

      INSERT WA_NUMBER INTO TABLE IT_NUMBER.

endif.

So first time it will show like what ever you want to. Please debug it to understand it better

Nabheet

3 REPLIES 3

nabheetscn
SAP Champion
SAP Champion
0 Kudos
296

Souvik

First of when your screen is called PBO will be called and at that time your internal table is empty so its displaying blank records. When you press next then you are filling the data. What you should do is in PBO check if IT_NUMBER is initial then

     WA_NUMBER-NUMBER01 = '12344'.

      INSERT WA_NUMBER INTO TABLE IT_NUMBER.

endif.

So first time it will show like what ever you want to. Please debug it to understand it better

Nabheet

Former Member
0 Kudos
295

Hi Souvik,

                In MODULE USER_COMMAND_0100 declare a count variable and do not increment the variable LINE for the first time 'NEXT' is being clicked. because this is what affects the variable IDX in PBO and IDX will never be 1.

ie,  sumthng like this,

IN MODULE USER_COMMAND_0100, code is:

CASE SY-UCOMM.


    WHEN 'NEXT'.
        WA_NUMBER-NUMBER01 = '12344'.
      INSERT WA_NUMBER INTO TABLE IT_NUMBER.
      WA_NUMBER-NUMBER01 = '12345'.
      INSERT WA_NUMBER INTO TABLE IT_NUMBER.
      WA_NUMBER-NUMBER01 = '12346'.
      INSERT WA_NUMBER INTO TABLE IT_NUMBER.
      WA_NUMBER-NUMBER01 = '12347'.
      INSERT WA_NUMBER INTO TABLE IT_NUMBER.
      WA_NUMBER-NUMBER01 = '12348'.
      INSERT WA_NUMBER INTO TABLE IT_NUMBER.
      WA_NUMBER-NUMBER01 = '12349'.
      INSERT WA_NUMBER INTO TABLE IT_NUMBER.
      DESCRIBE TABLE IT_NUMBER LINES FILL.

     If V_COUNT > 1.

      LINE = LINE + 1.

     endif.

   

      V_COUNT = V_COUNT +1.

    

CALL SCREEN 100.

Hope this Helps.

Happy Coding,

Santhosh Yadav

0 Kudos
295

Hi,

I have tried your snippet but it's not working unfortunately. Only the first record is getting populated. The rest of the records are not coming at all after using the counter.