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

Subroutine in smartform

Former Member
0 Likes
704

In my smartform I need to write a sub routine and compute a value to be displayed in smartform. I have been able to accomplish this as a test program but unable to integrate it as a sub routine in my smart form partly because I am new to sub routines.

I need to find J_3AFCC value from MARA where matnr = gs_it_gen-material

Do I have to declare an internal table to put the J_3AFCC and how to do it

Also do I have to declare structure gs_it_gen as currently it says gs_it_gen-material field is unknown

Then I need to use the xvalues field and pass it in my smartform. Any help will be greatly appreciated. Thank you

*&---------------------------------------------------------------------*
*&      Form  fcc_values
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM fcc_values.

  DATA: BEGIN OF xvalues OCCURS 100,
        text(64) TYPE c,
        END OF xvalues,

        ij_3afcco  LIKE j_3afcco  OCCURS 20 WITH HEADER LINE,
        ij_3afcfab LIKE j_3afcfab OCCURS 50 WITH HEADER LINE,
        ij_3afabt  LIKE j_3afabt  OCCURS 10 WITH HEADER LINE,
        h_fcctext  LIKE j_3amatdi-fcctext,
        h_fcc2     LIKE j_3amatdi-fcctext,
        h_text     LIKE j_3amatdi-fcctext,
        h_tabix    LIKE sy-tabix.
        
        data: lv_j_3afcc like mara-j_3afcc.

* Using IT_GEN-MATERIAL find J_3AFCC from MARA
  "SELECT J_3AFCC from mara into lv_j_3afcc where matnr = gs_it_gen-material.
  SELECT * FROM j_3afcco  INTO TABLE ij_3afcco  WHERE j_3afcc = '004'.
  SELECT * FROM j_3afcfab INTO TABLE ij_3afcfab WHERE j_3afcc = '004'.
  SELECT * FROM j_3afabt  INTO TABLE ij_3afabt  WHERE spras = sy-langu.

  SORT ij_3afcfab BY j_3afcc j_3afcseq.
  CLEAR xvalues.
  LOOP AT ij_3afcco.
    MOVE ij_3afcco-j_3afcc TO xvalues.
    APPEND xvalues.
    CLEAR xvalues.
    CLEAR h_text.
    CLEAR h_tabix.
    LOOP AT ij_3afcfab WHERE j_3afcc = ij_3afcco-j_3afcc.
      ADD 1 TO h_tabix.
      READ TABLE ij_3afabt WITH KEY j_3afabr = ij_3afcfab-j_3afabr.
      IF sy-subrc NE 0.
        CLEAR ij_3afabt.
      ENDIF.
      h_fcc2 = h_text.
      WRITE ij_3afcfab-proz TO h_fcctext NO-ZERO.
      h_fcctext+6 = '%'.
      CONDENSE h_fcctext NO-GAPS.
      h_fcctext+10 = ij_3afabt-text.
      CONDENSE h_fcctext.
      IF h_tabix = 1.
        CONCATENATE h_fcc2 h_fcctext INTO h_text.
      ELSE.
        CONCATENATE h_fcc2 h_fcctext INTO h_text
                    SEPARATED BY '/'.
      ENDIF.
    ENDLOOP.
    MOVE h_text TO xvalues.
    APPEND xvalues.
  ENDLOOP.

  WRITE xvalues.

ENDFORM.                    "fcc_values

In my smartform I need to write a sub routine and compute a value to be displayed in smartform. I have been able to accomplish this as a test program but unable to integrate it as a sub routine in my smart form partly because I am new to sub routines.

I need to find J_3AFCC value from MARA where matnr = gs_it_gen-material

Do I have to declare an internal table to put the J_3AFCC and how to do it

Also do I have to declare structure gs_it_gen as currently it says gs_it_gen-material field is unknown

Then I need to use the xvalues field and pass it in my smartform. Any help will be greatly appreciated. Thank you

*&---------------------------------------------------------------------*
*&      Form  fcc_values
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM fcc_values.

  DATA: BEGIN OF xvalues OCCURS 100,
        text(64) TYPE c,
        END OF xvalues,

        ij_3afcco  LIKE j_3afcco  OCCURS 20 WITH HEADER LINE,
        ij_3afcfab LIKE j_3afcfab OCCURS 50 WITH HEADER LINE,
        ij_3afabt  LIKE j_3afabt  OCCURS 10 WITH HEADER LINE,
        h_fcctext  LIKE j_3amatdi-fcctext,
        h_fcc2     LIKE j_3amatdi-fcctext,
        h_text     LIKE j_3amatdi-fcctext,
        h_tabix    LIKE sy-tabix.
        
        data: lv_j_3afcc like mara-j_3afcc.

* Using IT_GEN-MATERIAL find J_3AFCC from MARA
  "SELECT J_3AFCC from mara into lv_j_3afcc where matnr = gs_it_gen-material.
  SELECT * FROM j_3afcco  INTO TABLE ij_3afcco  WHERE j_3afcc = '004'.
  SELECT * FROM j_3afcfab INTO TABLE ij_3afcfab WHERE j_3afcc = '004'.
  SELECT * FROM j_3afabt  INTO TABLE ij_3afabt  WHERE spras = sy-langu.

  SORT ij_3afcfab BY j_3afcc j_3afcseq.
  CLEAR xvalues.
  LOOP AT ij_3afcco.
    MOVE ij_3afcco-j_3afcc TO xvalues.
    APPEND xvalues.
    CLEAR xvalues.
    CLEAR h_text.
    CLEAR h_tabix.
    LOOP AT ij_3afcfab WHERE j_3afcc = ij_3afcco-j_3afcc.
      ADD 1 TO h_tabix.
      READ TABLE ij_3afabt WITH KEY j_3afabr = ij_3afcfab-j_3afabr.
      IF sy-subrc NE 0.
        CLEAR ij_3afabt.
      ENDIF.
      h_fcc2 = h_text.
      WRITE ij_3afcfab-proz TO h_fcctext NO-ZERO.
      h_fcctext+6 = '%'.
      CONDENSE h_fcctext NO-GAPS.
      h_fcctext+10 = ij_3afabt-text.
      CONDENSE h_fcctext.
      IF h_tabix = 1.
        CONCATENATE h_fcc2 h_fcctext INTO h_text.
      ELSE.
        CONCATENATE h_fcc2 h_fcctext INTO h_text
                    SEPARATED BY '/'.
      ENDIF.
    ENDLOOP.
    MOVE h_text TO xvalues.
    APPEND xvalues.
  ENDLOOP.

  WRITE xvalues.

ENDFORM.                    "fcc_values

4 REPLIES 4
Read only

Former Member
0 Likes
659

Perhaps we can do this first in a test program. I think I should be able to integrate this into my form then. All I want is to be able to convert this into form perform

Read only

Former Member
0 Likes
659

in the smartform, right click to "create" an element, and select "program lines" (in ECC6, this is flow logic->program lines".

You will see three areas on the screen. One for inbound parameters, one for outbound parameters and one for code.

Any data local to the routine (your "data" statements) does not have to be in the input or output parameter areas.

Anything you want to use from the outside (a global variable, for example, or something from the form interface) must be declared as input, output, or both.

Insert the code lines element someplace BEFORE you want to use the output from the code.

If you want to use the XVALUES outside of the code, for instance, to create a table of data on the form, you will need to define it globally to the form.

Read only

Former Member
0 Likes
659

Right now I am just looking at making a subroutine out of my code and be able to display xvalues after running the subroutine.

Read only

Former Member
0 Likes
659

Wrong solution, will post this again in another thread