Application Development 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: 

subroutine

Former Member
0 Kudos

Hi ,

I am trying to do the following code into a form.

I must send a single field F while calling a form in the main program...

I must get it into 2 fields p1 & p2.

How I do I write the perform

<b>data: str type string.

data: p1 type string.

data: p2 type string.

data: offset type i.

data: len type i.

data: lowercase type sy-abcde.

lowercase = sy-abcde.

translate lowercase to LOWER CASE.

str = '14.8KG g'.

TRANSLATE str using ' %'.

len = strlen( str ).

len = len - 1.

do len times.

offset = offset + 1.

if str+offset(1) ca '0123456789.'.

concatenate p1 str+offset(1) into p1.

elseif ( str+offset(1) ca sy-abcde

or str+offset(1) ca lowercase

or str+offset(1) = '%' ).

concatenate p2 str+offset(1) into p2.

endif.

enddo.

TRANSLATE p2 using '% '.

write:/ p1, p2.

</b>

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Here is an example using your code and passing parameters to the FORM (or you could just make the variables global):

  DATA: v_1 TYPE STRING,
        v_2 TYPE STRING,
        v_3 TYPE STRING.

  v_1 = '14.8KG g'.

  PERFORM F_FORM USING v_1 v_2 v_3.

  Write:/ v_2, v_3.
*---------------------------------------------------------------------*
*       FORM F_FORM                                                   *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  V_STRING1                                                     *
*  -->  V_STRING2                                                     *
*  -->  V_STRING3                                                     *
*---------------------------------------------------------------------*
FORM F_FORM USING v_string1 v_string2 v_string3.
  data: str type string.
  data: p1 type string.
  data: p2 type string.
  data: offset type i.
  data: len type i.
  data: lowercase type sy-abcde.

  lowercase = sy-abcde.
  translate lowercase to LOWER CASE.

*  str = '14.8KG g'.
  str = V_STRING1.

  TRANSLATE str using ' %'.
  len = strlen( str ).
  len = len - 1.

  do len times.

    offset = offset + 1.
    if str+offset(1) ca '0123456789.'.
      concatenate p1 str+offset(1) into p1.
    elseif ( str+offset(1) ca sy-abcde
    or str+offset(1) ca lowercase
    or str+offset(1) = '%' ).
      concatenate p2 str+offset(1) into p2.
    endif.

  enddo.

  TRANSLATE p2 using '% '.

*  write:/ p1, p2.
   v_string2 = p1.
   v_string3 = p2.

ENDFORM.

3 REPLIES 3

Former Member
0 Kudos

You can use following:

PERFORM <performname> USING <var1> <var2>

However, i think formal and actual parameters must be same.

Thanks,

Santosh

Former Member
0 Kudos

Here is an example using your code and passing parameters to the FORM (or you could just make the variables global):

  DATA: v_1 TYPE STRING,
        v_2 TYPE STRING,
        v_3 TYPE STRING.

  v_1 = '14.8KG g'.

  PERFORM F_FORM USING v_1 v_2 v_3.

  Write:/ v_2, v_3.
*---------------------------------------------------------------------*
*       FORM F_FORM                                                   *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  V_STRING1                                                     *
*  -->  V_STRING2                                                     *
*  -->  V_STRING3                                                     *
*---------------------------------------------------------------------*
FORM F_FORM USING v_string1 v_string2 v_string3.
  data: str type string.
  data: p1 type string.
  data: p2 type string.
  data: offset type i.
  data: len type i.
  data: lowercase type sy-abcde.

  lowercase = sy-abcde.
  translate lowercase to LOWER CASE.

*  str = '14.8KG g'.
  str = V_STRING1.

  TRANSLATE str using ' %'.
  len = strlen( str ).
  len = len - 1.

  do len times.

    offset = offset + 1.
    if str+offset(1) ca '0123456789.'.
      concatenate p1 str+offset(1) into p1.
    elseif ( str+offset(1) ca sy-abcde
    or str+offset(1) ca lowercase
    or str+offset(1) = '%' ).
      concatenate p2 str+offset(1) into p2.
    endif.

  enddo.

  TRANSLATE p2 using '% '.

*  write:/ p1, p2.
   v_string2 = p1.
   v_string3 = p2.

ENDFORM.

0 Kudos

Thanks Nagel !