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

SAP Script help

Former Member
0 Likes
439

Hi all,

I need to format the o/p of a data in the script.the requirment is to give 2 spaces after every 2 characters.

for ex:if the data is 'WR56T8' then the o/p format should be 'WR 56 T8'.how can i do it in the script?i am not supposed to change the print program..so i cant use PERFORM in the script..

Thanks..

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
409

HI RAKESH,

EVEN IF U CANT CHANGE THE DRIVER PROGRAM U CAN STILL WRITE A PERFORM IN THE SCRIPT as the driver program will be calling ur script.

/: PERFORM get_value IN PROGRAM ZTEST

/: USING VAR1

/: CHANGING VAR2

/: ENDPERFORM.

FORM get-value TABLES IN_TAB STRUCTURE ITCSY

OUT_TAB STRUCTURE ITCSY.

DATA: STR TYPE STRING,

STR1 TYPE STRING,

STR2 TYPE STRING,

STR3 TYPE STRING.

READ TABLE IN_TAB WITH KEY NAME = VAR1.

IF SY-SUBRC = 0.

MOVE IN_TAB-VALUE TO str.

ENDIF.

str1 = str+0(2).

str2 = str+2(4).

str3 = str+4(6).

concatenate str1 str2 str3 into var2 separated by space.

READ TABLE OUT_TAB WITH KEY NAME = VAR2.

IF SY-SUBRC = 0.

MOVE VAR2 TO OUT_TAB-VALUE.

MODIFY OUT_TAB INDEX SY-TABIX.

ENDIF.

ENDFORM.

so whenever ur form is called and when the cursor goes to perform stmt it will go to the program ZTEST and execute.

2 REPLIES 2
Read only

Former Member
0 Likes
409

You use perform ONLY in case where you can't change the print program.

So you can use the perforsm in sap script.

/: PERFORM convert IN PROGRAM Ztest

/: USING &INPUT&

/: CHANGING &OUTPUT&

/: ENDPERFORM

in ztest:

FORM convert TABLES sap_data STRUCTURE itcsy

abap_data STRUCTURE itcsy.

DATA: V_OUTPUT(8).

READ TABLE sap_data WITH KEY name = 'INPUT'.

IF sy-subrc EQ 0.

CONCATENATE INPUT+0(2)

INPUT+2(2)

INPUT+4(2)

INTO V_OUTPUT SEPARATED BY SPACE.

ENDIF.

CONDENSE V_OUTPUT NO-GAPS.

READ TABLE abap_data WITH KEY name = 'OUTPUT'.

IF sy-subrc EQ 0.

abap_data-value = V_OUTPUT.

MODIFY abap_data INDEX sy-tabix.

ENDIF.

ENDFORM.

Read only

Former Member
0 Likes
410

HI RAKESH,

EVEN IF U CANT CHANGE THE DRIVER PROGRAM U CAN STILL WRITE A PERFORM IN THE SCRIPT as the driver program will be calling ur script.

/: PERFORM get_value IN PROGRAM ZTEST

/: USING VAR1

/: CHANGING VAR2

/: ENDPERFORM.

FORM get-value TABLES IN_TAB STRUCTURE ITCSY

OUT_TAB STRUCTURE ITCSY.

DATA: STR TYPE STRING,

STR1 TYPE STRING,

STR2 TYPE STRING,

STR3 TYPE STRING.

READ TABLE IN_TAB WITH KEY NAME = VAR1.

IF SY-SUBRC = 0.

MOVE IN_TAB-VALUE TO str.

ENDIF.

str1 = str+0(2).

str2 = str+2(4).

str3 = str+4(6).

concatenate str1 str2 str3 into var2 separated by space.

READ TABLE OUT_TAB WITH KEY NAME = VAR2.

IF SY-SUBRC = 0.

MOVE VAR2 TO OUT_TAB-VALUE.

MODIFY OUT_TAB INDEX SY-TABIX.

ENDIF.

ENDFORM.

so whenever ur form is called and when the cursor goes to perform stmt it will go to the program ZTEST and execute.