Wednesday, April 9, 2008

SAP ABAP Converting from Upper Case to Lower Case

SAP ABAP Converting from Upper Case to Lower Case

SAP ABAP Translate Statement

In ABAP we can use TRANSLATE statement to change the case of characters. This means that if you want to  programatically convert any characters to upper case or to lower case then it can be done using the TRANSLATE statement.

There is another variation of  TRANSLATE statement in which you can translate characters in STRING1 as per the rules given in STRING2.

Please see the examples given below.

DATA: d_PH(17) VALUE 'PeAcEaNdHaRmOny',
d_Translate LIKE d_PH,
RULE(30) VALUE 'PHeEAAcLETaHNYdLHIaVRImNOGn y '.

d_Translate = d_PH.
WRITE d_Translate.

TRANSLATE d_Translate TO UPPER CASE.
WRITE / d_Translate.

d_Translate = d_PH.
TRANSLATE d_Translate TO LOWER CASE.
WRITE / d_Translate.

d_Translate = d_PH.
TRANSLATE d_Translate USING RULE.
WRITE / d_Translate.

Output of the above code will be as follows.

Translate examples   
                     
PeAcEaNdHaRmOny      
PEACEANDHARMONY      
peaceandharmony      
HEALTHYLIHING        


No comments:

Post a Comment