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: 
Read only

Reduce Lines of Code - Using ASSIGN ?

Former Member
0 Likes
640

Hi All,

My requirement is very simple, I just want to reduce my lines of code. I came to know, this can be done by using ASSIGN statement.

Please guide me in achieving this. Please find the below code for example.

CASE ok_code.
    WHEN 'EXEC'.
      SELECT SINGLE matnr FROM mara INTO gwa_0110_val
            WHERE matnr EQ zmm_s_mat_rep-new_material.
      IF sy-subrc EQ 0.
        IF gv_count = 0.
          gwa_0110-new_mat1 = zmm_s_mat_rep-new_material.
          gwa_0110-new_qty1 = zmm_s_mat_rep-new_qty.
          gwa_0110-line_no = tc110-current_line.
          IF gv_sel1 = 'X'.
            gwa_0110-sel1 = 'X'.
          ENDIF.
        ENDIF.

        IF gv_count = 1.
          gwa_0110-new_mat2 = zmm_s_mat_rep-new_material.
          gwa_0110-new_qty2 = zmm_s_mat_rep-new_qty.
          gwa_0110-line_no = tc110-current_line.
          IF gv_sel1 = 'X'.
            gwa_0110-sel1 = 'X'.
          ENDIF.
        ENDIF.

        IF gv_count = 2.
          gwa_0110-new_mat3 = zmm_s_mat_rep-new_material.
          gwa_0110-new_qty3 = zmm_s_mat_rep-new_qty.
          gwa_0110-line_no = tc110-current_line.
          IF gv_sel1 = 'X'.
            gwa_0110-sel1 = 'X'.
          ENDIF.
        ENDIF.

        IF gv_count = 3.
          gwa_0110-new_mat4 = zmm_s_mat_rep-new_material.
          gwa_0110-new_qty4 = zmm_s_mat_rep-new_qty.
          gwa_0110-line_no = tc110-current_line.
          IF gv_sel1 = 'X'.
            gwa_0110-sel1 = 'X'.
          ENDIF.
        ENDIF.

        IF gv_count = 4.
          gwa_0110-new_mat5 = zmm_s_mat_rep-new_material.
          gwa_0110-new_qty5 = zmm_s_mat_rep-new_qty.
          gwa_0110-line_no = tc110-current_line.
          IF gv_sel1 = 'X'.
            gwa_0110-sel1 = 'X'.
          ENDIF.
        ENDIF.

      ELSE.
        MESSAGE i014(z_mm_prox).
      ENDIF.
      CLEAR gwa_0110_val.
      APPEND gwa_0110 TO git_0110.
      CLEAR gwa_0110.

zmm_s_mat_rep - Structure(Screen 110)

Thanks,

Chandan

Hi All,

My requirement is very simple, I just want to reduce my lines of code. I came to know, this can be done by using ASSIGN statement.

Please guide me in achieving this. Please find the below code for example.

CASE ok_code.
    WHEN 'EXEC'.
      SELECT SINGLE matnr FROM mara INTO gwa_0110_val
            WHERE matnr EQ zmm_s_mat_rep-new_material.
      IF sy-subrc EQ 0.
        IF gv_count = 0.
          gwa_0110-new_mat1 = zmm_s_mat_rep-new_material.
          gwa_0110-new_qty1 = zmm_s_mat_rep-new_qty.
          gwa_0110-line_no = tc110-current_line.
          IF gv_sel1 = 'X'.
            gwa_0110-sel1 = 'X'.
          ENDIF.
        ENDIF.

        IF gv_count = 1.
          gwa_0110-new_mat2 = zmm_s_mat_rep-new_material.
          gwa_0110-new_qty2 = zmm_s_mat_rep-new_qty.
          gwa_0110-line_no = tc110-current_line.
          IF gv_sel1 = 'X'.
            gwa_0110-sel1 = 'X'.
          ENDIF.
        ENDIF.

        IF gv_count = 2.
          gwa_0110-new_mat3 = zmm_s_mat_rep-new_material.
          gwa_0110-new_qty3 = zmm_s_mat_rep-new_qty.
          gwa_0110-line_no = tc110-current_line.
          IF gv_sel1 = 'X'.
            gwa_0110-sel1 = 'X'.
          ENDIF.
        ENDIF.

        IF gv_count = 3.
          gwa_0110-new_mat4 = zmm_s_mat_rep-new_material.
          gwa_0110-new_qty4 = zmm_s_mat_rep-new_qty.
          gwa_0110-line_no = tc110-current_line.
          IF gv_sel1 = 'X'.
            gwa_0110-sel1 = 'X'.
          ENDIF.
        ENDIF.

        IF gv_count = 4.
          gwa_0110-new_mat5 = zmm_s_mat_rep-new_material.
          gwa_0110-new_qty5 = zmm_s_mat_rep-new_qty.
          gwa_0110-line_no = tc110-current_line.
          IF gv_sel1 = 'X'.
            gwa_0110-sel1 = 'X'.
          ENDIF.
        ENDIF.

      ELSE.
        MESSAGE i014(z_mm_prox).
      ENDIF.
      CLEAR gwa_0110_val.
      APPEND gwa_0110 TO git_0110.
      CLEAR gwa_0110.

zmm_s_mat_rep - Structure(Screen 110)

Thanks,

Chandan

3 REPLIES 3
Read only

Former Member
0 Likes
601

Hi Chandan,

You can reduce number of lines simply by

CASE ok_code.
    WHEN 'EXEC'.
      SELECT SINGLE matnr FROM mara INTO gwa_0110_val
            WHERE matnr EQ zmm_s_mat_rep-new_material.
      IF sy-subrc EQ 0.
        IF ( gv_count eq 0 ) or
           ( gv_count eq 1) or 
          ( gv_count eq 2 ) or 
          ( gv_count eq 3 ) or
         ( gv_count eq 4 ).

          gwa_0110-new_mat1 = zmm_s_mat_rep-new_material.
          gwa_0110-new_qty1 = zmm_s_mat_rep-new_qty.
          gwa_0110-line_no = tc110-current_line.
          IF gv_sel1 = 'X'.
            gwa_0110-sel1 = 'X'.
          ENDIF.
        ENDIF.
 
        
      ELSE.
        MESSAGE i014(z_mm_prox).
      ENDIF.

Hope this resolves your query.

Regards,

Manish

Edited by: Manish Bisht on Jun 29, 2009 7:46 AM

Edited by: Manish Bisht on Jun 29, 2009 7:47 AM

Read only

venkat_o
Active Contributor
0 Likes
601

Hi Chandan,

ASSIGN mem_area TO <fs>.
<li>This statement assigns the memory area specified using mem_area to the field symbol <fs>. <li>You can use modify your code like this. There is no wrong in your code actually. I dont understand what the problem is in your code.

ASSIGN
CASE ok_code.
  WHEN 'EXEC'.
    SELECT SINGLE matnr FROM mara INTO gwa_0110_val
          WHERE matnr EQ zmm_s_mat_rep-new_material.
    IF sy-subrc EQ 0.
      CASE gv_count.
        WHEN 0.
          PERFORM get_qty CHANGING gwa_0110-new_mat1
                                   gwa_0110-new_qty1
                                   gwa_0110-line_no
                                   gwa_0110-sel1.
        WHEN 1.
          PERFORM get_qty CHANGING gwa_0110-new_mat1
                                   gwa_0110-new_qty1
                                   gwa_0110-line_no
                                   gwa_0110-sel1.
        WHEN 2.
          PERFORM get_qty CHANGING gwa_0110-new_mat1
                                   gwa_0110-new_qty1
                                   gwa_0110-line_no
                                   gwa_0110-sel1.
        WHEN 3.
          PERFORM get_qty CHANGING gwa_0110-new_mat1
                                   gwa_0110-new_qty1
                                   gwa_0110-line_no
                                   gwa_0110-sel1.
        WHEN 4.
          PERFORM get_qty CHANGING gwa_0110-new_mat1
                                   gwa_0110-new_qty1
                                   gwa_0110-line_no
                                   gwa_0110-sel1.
      ENDCASE.
    ELSE.
      MESSAGE i014(z_mm_prox).
    ENDIF.
    CLEAR gwa_0110_val.
    APPEND gwa_0110 TO git_0110.
    CLEAR gwa_0110.
ENDCASE.

*&---------------------------------------------------------------------*
*&      Form  GET_qty
*&---------------------------------------------------------------------*
FORM get_qty CHANGING mat qty line_no sel.
  mat = zmm_s_mat_rep-new_material.
  qty = zmm_s_mat_rep-new_qty.
  line_no = tc110-current_line.
  IF gv_sel1 = 'X'.
    sel = 'X'.
  ENDIF.
ENDFORM.                    "GET_qty
Thanks Venkat.O

Read only

Former Member
0 Likes
601

Solved