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: 

fetching data in sap script

Former Member
0 Kudos
1,610

hi, i am unable to fetch data in my sap script

for the feild :bseg-sgtxt.

So, i have to write a form-perform code to get data.

the feilds which i have are bseg-belnr and bseg-buzei.

can anyone help me with the code to include in sap script

perform as well as form ?

rgds,

Ravindra

1 ACCEPTED SOLUTION
7 REPLIES 7

Former Member
0 Kudos
690

*In SAP SCRIPT you can write

/: PERFORM ADD_INCOME IN PROGRAM Z_MYINCLUDE_NAME
/: USING &var1&
/: USING &var1&
/: CHANGING &var2&
/: CHANGING &var2&
/: ENDPERFORM.

Include you can write your code inside.

FORM MYFORM TABLES IN_TAB STRUCTURE ITCSY
                          OUT_TAB STRUCTURE ITCSY.

* update out_tab for the returing parameters to SAP SCRIPT

ENDFORM.

Cheers,

Thomas.

Bema
Active Participant
0 Kudos
690

Syntax in a form window:

/: PERFORM <form> IN PROGRAM <prog>

/: USING &INVAR1&

/: USING &INVAR2&

......

/: CHANGING &OUTVAR1&

/: CHANGING &OUTVAR2&

......

/: ENDPERFORM

INVAR1 and INVAR2 are variable symbols and may be of any of the four SAP script symbol types.

OUTVAR1 and OUTVAR2 are local text symbols and must therefore be character strings.

The ABAP subroutine called via the command line stated above must be defined in the ABAP report program as follows:

FORM <form> TABLES IN_TAB STRUCTURE ITCSY

OUT_TAB STRUCTURE ITCSY.

...

ENDFORM.

The values of the SAP script symbols passed with /: USING... are now stored in the internal table IN_TAB. Hence values passed can be accessed form this internal table and used for further processing. The internal table OUT_TAB contains names and values of the CHANGING parameters in the PERFORM statement. By this way the changes or calculation made using the local symbols in the subroutine can be passed back to the form for printing. OUT_TAB is also of type ITSCY.

Example

Perform called in text editor of form.

/E PERFORM_ABAP

/: PERFORM CALLED_FROM_SAPSCRIPT IN PROGRAM zsapscriptexits

/: USING &invar1&

/: USING &invar2&

/: CHANGING &outvar1&

/: CHANGING &outvar2&

/: ENDPERFORM

<b>Abap subroutine</b>

FORM CALLED_FROM_SAPSCRIPT

TABLES IN_TAB STRUCTURE ITCSY

OUT_TAB STRUCTURE ITCSY.

DATA: TABIX LIKE SY-TABIX.

TABLES: KNA1.

READ TABLE IN_TAB WITH KEY NAME = 'KUNNR'.

KNA1-KUNNR = IN_TAB-VALUE.

READ TABLE OUT_TAB WITH KEY NAME = 'NAME'.

TABIX = SY-TABIX.

OUT_TAB-NAME = 'NAME'.

SELECT SINGLE * FROM KNA1 WHERE KUNNR EQ KNA1-KUNNR.

IF SY-SUBRC EQ 0.

CONCATENATE KNA1-NAME1 KNA1-ORT01 INTO OUT_TAB-VALUE

SEPARATED BY SPACE.

ELSE.

CONCATENATE KNA1-KUNNR 'not found' INTO OUT_TAB-VALUE

SEPARATED BY SPACE.

ENDIF.

MODIFY OUT_TAB INDEX TABIX.

ENDFORM.

Former Member
0 Kudos
690

Hi Ravindra,

Use this format

IN SCRIPT:

/: PERFORM GET_BARCODE6 IN PROGRAM ZVXR0076

/* USING &BARCV&

/: USING &BARC6&

/: CHANGING &BARCODE&

/: ENDPERFORM

IN PROGRAM ZVXR0076

FORM get_barcode TABLES sap_data STRUCTURE itcsy

abap_data STRUCTURE itcsy.

DATA : barcv LIKE karte-barcv,

barcode(11).

READ TABLE sap_data WITH KEY name = 'BARCV'.

IF sy-subrc EQ 0.

MOVE sap_data-value TO barcv.

ENDIF.

WRITE barcv TO barcode NO-ZERO.

CONDENSE barcode NO-GAPS.

READ TABLE abap_data WITH KEY name = 'BARCODE'.

IF sy-subrc EQ 0.

abap_data-value = barcode.

MODIFY abap_data INDEX sy-tabix.

ENDIF.

ENDFORM. "GET_BARCODE

Former Member
0 Kudos
690

This seems to be a very common problem. actually the bseg-sgtext field is normally blank( as in our case here)..so first chk out in the table BSEG if this field has any value for ur data. & if no data is popluated obviously it wont come in your printout...

hope it helps..

0 Kudos
384

Hello,

I have write a perform to fetch data and call that perform on script form also but while debugging internal input table gets empty and i am not able to understand why this happening.

 

0 Kudos
382

Hello but in my case bseg-sgtxt field is not blank it has values for all documents still its display as empty on script form