Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
The SAP Community wiki will be closed to new content submissions from December 7 6:00 p.m. CET to December 11 6:00 p.m. CET.
All content created during this period will not be available/restorable after December 11.
We apologize for the inconvenience, but we need to take this action to improve and maintain the SAP Community wiki performance.
Please plan your tasks accordingly.
Skip to end of metadata
Go to start of metadata

 

Program to generalize the conversion exits dynamically

 

Summary

This program demonstrates how to generalize the conversion exits dynamically. It holds only the template for how to be done. Further modifications are applicable as required.Check the attachments to view the Inputs/Outputs. For example in this program i have used vendor no, material no and material characteristics for conversions.

Author(s):     

Name: Kesavadas Thekkillath

Company: Atos

Source Code

Error rendering macro 'code': Invalid value specified for parameter 'lang'
*--Variables
 DATA:WF_LENGTH TYPE I,
           WF_MASK   TYPE STRING.
*--Screen
 PARAMETERS:PA_MATNR TYPE MATNR, "Material No
                        PA_LIFNR TYPE LIFNR,        "Vendor No
                        PA_ATINN TYPE ATINN.    "Material characteristics
 PERFORM GENERALIZE_CONVERSIONS.
**&---------------------------------------------------------------------*
*  *&      FORM  GENERALIZE_CONVERSIONS
*  *&---------------------------------------------------------------------*
 FORM GENERALIZE_CONVERSIONS.
   DATA:LF_LENGTH TYPE I,
              LF_MASK   TYPE STRING.
*--Material No
   CLEAR:LF_MASK, LF_LENGTH.
   PERFORM GET_MASK_LENGTH USING    'PA_MATNR'  CHANGING  LF_LENGTH LF_MASK.
   PERFORM CONVERT USING 'PA_MATNR' PA_MATNR LF_LENGTH LF_MASK.
*--Vendor No
   CLEAR:LF_MASK,LF_LENGTH.
   PERFORM GET_MASK_LENGTH USING    'PA_LIFNR' CHANGING LF_LENGTH LF_MASK.
   PERFORM CONVERT USING 'PA_LIFNR' PA_LIFNR LF_LENGTH LF_MASK.
*--Material Characteristics
   CLEAR:LF_MASK,LF_LENGTH.
   PERFORM GET_MASK_LENGTH USING    'PA_ATINN' CHANGING LF_LENGTH LF_MASK.
   PERFORM CONVERT USING 'PA_ATINN' PA_ATINN LF_LENGTH LF_MASK.
 ENDFORM.                    " GENERALIZE_CONVERSIONS
*  *&---------------------------------------------------------------------*
*  *&      FORM  GET_MASK_LENGTH
*  *&---------------------------------------------------------------------*
*  *       TEXT
*  *----------------------------------------------------------------------*
*  *      -->P_0042   TEXT
*  *      <--P_LF_LENGTH  TEXT
*  *----------------------------------------------------------------------*
 FORM GET_MASK_LENGTH  USING    VALUE(P_0042) TYPE ANY
                                         CHANGING PC_LENGTH TYPE I
                                                           PC_MASK TYPE STRING.
   FIELD-SYMBOLS:<FS> TYPE ANY.
*--Read the mask associated with the domain
    *  AND THE TOTAL OUTPUT LENGTH OF THE FIELD
     ASSIGN (P_0042) TO <FS>.
   CHECK SY-SUBRC = 0.
   DESCRIBE FIELD <FS> OUTPUT-LENGTH PC_LENGTH
                                        EDIT MASK PC_MASK.
   REPLACE '==' IN PC_MASK WITH ` `.
   CONDENSE PC_MASK NO-GAPS.
 ENDFORM.                    " GET_MASK_LENGTH
* *&---------------------------------------------------------------------*
* *&      FORM  CONVERT
* *&---------------------------------------------------------------------*
* *       TEXT
* *----------------------------------------------------------------------*
* *  -->  P1        TEXT
* *  <--  P2        TEXT
* *----------------------------------------------------------------------*
 FORM CONVERT USING PU_FIELD TYPE ANY
                                    PU_VALUE TYPE ANY
                                    PU_LENGTH TYPE I
                                    PU_MASK TYPE STRING .
   DATA:LF_CONVEXIT    TYPE FUNCNAME,
                I_COMP         TYPE CL_ABAP_STRUCTDESCR=>COMPONENT_TABLE,
                WA_COMP     LIKE LINE OF I_COMP,
               WF_TYPE_STRUCT TYPE REF TO CL_ABAP_STRUCTDESCR,
                WF_DATA_STR     TYPE REF TO DATA. .
   FIELD-SYMBOLS:<FS_T>  TYPE ANY,
                              <FS_WA> TYPE ANY.
*--Dynamically create a target field based on the output length which fits the value returned by the conversion exit.
   CLEAR:I_COMP[], WA_COMP.
   WA_COMP-NAME = 'FIELD'.
   WA_COMP-TYPE ?= CL_ABAP_ELEMDESCR=>GET_C( PU_LENGTH ).
   APPEND WA_COMP TO I_COMP.
   TRY.
       WF_TYPE_STRUCT = CL_ABAP_STRUCTDESCR=>CREATE( P_COMPONENTS = I_COMP ).
     CATCH CX_SY_STRUCT_CREATION.
   ENDTRY.
   CREATE DATA : WF_DATA_STR TYPE HANDLE WF_TYPE_STRUCT.
   ASSIGN WF_DATA_STR->* TO <FS_WA>.
   CHECK SY-SUBRC = 0.
   ASSIGN COMPONENT 'FIELD' OF STRUCTURE <FS_WA> TO <FS_T>.
   CHECK SY-SUBRC = 0.
   WRITE:/.
   WRITE:/.
   WRITE :'Field Converted-',PU_FIELD.
*--Call the corresponding Conversion exit functio module based on the mask retrieved from the domain
   DO 2 TIMES.
     IF SY-INDEX = 1.
       CONCATENATE 'CONVERSION_EXIT_' PU_MASK '_INPUT' INTO LF_CONVEXIT.
     ELSE.
       CONCATENATE 'CONVERSION_EXIT_' PU_MASK '_OUTPUT' INTO LF_CONVEXIT.
     ENDIF.
     CALL FUNCTION LF_CONVEXIT
       EXPORTING
         INPUT  = PU_VALUE
       IMPORTING
         OUTPUT = <FS_T>.
     WRITE:/.
     WRITE: LF_CONVEXIT,'-',<FS_T>.
   ENDDO.
 ENDFORM.                    " CONVERT