cancel
Showing results for 
Search instead for 
Did you mean: 

If-Endif statement

Former Member
0 Kudos

Hi All,

I have the following code six times from matnr2 to matnr7. What is the best way to modify these statements.

If not gs_zcoop-matnr2 IS INITIAL.

WRITE: /01 sy-vline,

04 sy-vline,

07 sy-vline,

10 sy-vline,

13 sy-vline,

22 sy-vline,

53 sy-vline,

75 sy-vline,

89 sy-vline,

90 gs_zcoop-matnr2,

95 sy-vline,

96 gs_zcoop-prdct2,

135 sy-vline,

136 gs_zcoop-camount2,

151 sy-vline,

168 sy-vline,

184 sy-vline,

200 sy-vline,

203 sy-vline,

214 sy-vline,

225 sy-vline,

256 sy-vline,

268 sy-vline,

279 sy-vline,

285 sy-vline,

292 sy-vline,

307 sy-vline,

329 sy-vline,

340 sy-vline,

356 sy-vline.

ENDIF.

If not gs_zcoop-matnr3 IS INITIAL.

WRITE: /01 sy-vline,

04 sy-vline,

07 sy-vline,

10 sy-vline,

13 sy-vline,

22 sy-vline,

53 sy-vline,

75 sy-vline,

89 sy-vline,

90 gs_zcoop-matnr3,

95 sy-vline,

96 gs_zcoop-prdct3,

135 sy-vline,

136 gs_zcoop-camount3,

151 sy-vline,

168 sy-vline,

184 sy-vline,

200 sy-vline,

203 sy-vline,

214 sy-vline,

225 sy-vline,

256 sy-vline,

268 sy-vline,

279 sy-vline,

285 sy-vline,

292 sy-vline,

307 sy-vline,

329 sy-vline,

340 sy-vline,

356 sy-vline.

ENDIF.

Thanks,

Veni.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

If not gs_zcoop-matnr2 IS INITIAL.
perform write_line using gs_zcoop-matnr2 .
endif.

If not gs_zcoop-matnr3 IS INITIAL.
perform write_line using gs_zcoop-matnr3 .
endif.

...... etc

form write_line using p_var.

-


the rest of your code

Answers (2)

Answers (2)

Former Member
0 Kudos

hi veni reddy,

try it:

data:

l_tabix type sy-tabix,

l_matnr like gs_zcoop-matnr,

l_prdct like gs_zcoop-prdct,

l_camount like gs_zcoop-camount.

do 6 times.

l_tabix = sy-tabix.

clear: l_matnr, l_prdct, l_camount.

case l_tabix.

when 1.

l_matnr = gs_zcoop-matnr2.

l_prdct = gs_zcoop-prdct2.

l_camount = gs_zcoop-camount2.

when 2.

l_matnr = gs_zcoop-matnr3.

l_prdct = gs_zcoop-prdct3.

l_camount = gs_zcoop-camount3.

when 3.

l_matnr = gs_zcoop-matnr4.

l_prdct = gs_zcoop-prdct4.

l_camount = gs_zcoop-camount4.

when 4.

l_matnr = gs_zcoop-matnr5.

l_prdct = gs_zcoop-prdct5.

l_camount = gs_zcoop-camount5.

when 5.

l_matnr = gs_zcoop-matnr6.

l_prdct = gs_zcoop-prdct6.

l_camount = gs_zcoop-camount6.

when 6.

l_matnr = gs_zcoop-matnr7.

l_prdct = gs_zcoop-prdct7.

l_camount = gs_zcoop-camount7.

when others.

...

endcase.

If not l_matnr IS INITIAL.

WRITE: /01 sy-vline,

04 sy-vline,

07 sy-vline,

10 sy-vline,

13 sy-vline,

22 sy-vline,

53 sy-vline,

75 sy-vline,

89 sy-vline,

90 l_matnr,

95 sy-vline,

96 l_prdct,

135 sy-vline,

136 l_camount,

151 sy-vline,

168 sy-vline,

184 sy-vline,

200 sy-vline,

203 sy-vline,

214 sy-vline,

225 sy-vline,

256 sy-vline,

268 sy-vline,

279 sy-vline,

285 sy-vline,

292 sy-vline,

307 sy-vline,

329 sy-vline,

340 sy-vline,

356 sy-vline.

endif.

enddo.

naimesh_patel
Active Contributor
0 Kudos

You can use the Field-Symbols to avoid unnecessary Write Statements.

You can try like:


DATA: BEGIN OF ITAB OCCURS 0,
      FIELD1 TYPE CHAR30,
      FIELD2 TYPE CHAR30,
      FIELD3 TYPE CHAR30,
      END   OF ITAB.

FIELD-SYMBOLS: <FS> TYPE ANY.

DATA: L_CNT   TYPE CHAR10,
      L_FIELD TYPE CHAR30.

ITAB-FIELD1 = SY-ABCDE.
ITAB-FIELD3 = SY-ABCDE.
APPEND ITAB.

ITAB-FIELD1 = 1.
ITAB-FIELD2 = 2.
ITAB-FIELD3 = 3.
APPEND ITAB.

LOOP AT ITAB.
  DO 3 TIMES.
    L_CNT = SY-INDEX.
    CONDENSE L_CNT.
    CONCATENATE 'ITAB-FIELD' L_CNT INTO L_FIELD.
    ASSIGN (L_FIELD) TO <FS>.
    WRITE: / <FS>.
    ASSIGN SPACE TO <FS>.
  ENDDO.
  SKIP 1.
ENDLOOP.

Regards,

Naimesh Patel