Posted: Tue Sep 11, 2007 4:07 pm Post subject: Batch Input with 'Call Transaction'
Requirement:
Choose a transaction and write a Batch Input program with 'Call Transaction'. Do not use the Messagetab feature of 'Call Transaction'. In this case the last error message will be at the SY-MSG* system fields. Recreate the complete error message from table T100! (This example is also used by the demonstration of SY-MSG* system fields)
Solution:
Code:
REPORT ZSYSTEM LINE-SIZE 255.
TABLES: T100.
* Batch-input data
DATA: BEGIN OF G_BDCDATA OCCURS 100.
INCLUDE STRUCTURE BDCDATA.
DATA: END OF G_BDCDATA.
DATA: G_MESSAGE(200).
PERFORM FILL_BDCDATA.
CALL TRANSACTION 'FI01' USING G_BDCDATA MODE 'N'.
* of course it is nicer with a message itab, but this example
* should also demostrate the use of system variables.
SELECT SINGLE * FROM T100 WHERE SPRSL = 'E' AND ARBGB = SY-MSGID AND MSGNR = SY-MSGNO. G_MESSAGE = T100-TEXT.
PERFORM REPLACE_PARAMETERS USING SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 CHANGING G_MESSAGE.
WRITE: / 'System variables:'.
SKIP.
WRITE: / ' Sy-msgty:', SY-MSGTY.
WRITE: / ' Sy-msgid:', SY-MSGID.
WRITE: / ' Sy-msgno:', SY-MSGNO.
WRITE: / ' Sy-msgv1:', SY-MSGV1.
WRITE: / ' Sy-msgv2:', SY-MSGV2.
WRITE: / ' Sy-msgv3:', SY-MSGV3.
WRITE: / ' Sy-msgv4:', SY-MSGV4.
SKIP.
WRITE: / 'The transaction was called with a wrong country code.'.
WRITE: / 'The error message should be either that or that you have'.
WRITE: / ' no authorisation to execute the transaction'.
SKIP.
WRITE: / 'Message:'.
SKIP.
WRITE: / SY-MSGTY, G_MESSAGE.
*---------------------------------------------------------------------*
* Build up the BDC-table *
*---------------------------------------------------------------------*
FORM FILL_BDCDATA.
REFRESH G_BDCDATA.
PERFORM BDC_DYNPRO USING 'SAPMF02B' '0100'.
PERFORM BDC_FIELD USING 'BNKA-BANKS' 'ZZZ'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' 'QQQQQ'.
ENDFORM.
*---------------------------------------------------------------------*
* FORM BDC_DYNPRO *
*---------------------------------------------------------------------*
* Batchinput: Start new Dynpro *
*---------------------------------------------------------------------*
FORM REPLACE_PARAMETERS USING P_PAR_1
P_PAR_2
P_PAR_3
P_PAR_4
CHANGING P_MESSAGE.
* erst mal pruefen, ob numerierte Parameter verwendet wurden DO.
REPLACE '&1' WITH P_PAR_1 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&2' WITH P_PAR_2 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&3' WITH P_PAR_3 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&4' WITH P_PAR_4 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
* falls keine numerierten Parameter vorh., ersetzen wie gehabt
REPLACE '&' WITH P_PAR_1 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_2 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_3 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_4 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. "replace_parameters
Example 2: Drill Down to change Transaction Variants in Visible Mode.
Code:
REPORT Z_SHOW_VARIANTS .
TABLES : VARID.
DATA: ld_program LIKE syst-repid. "syrepid.
DATA: ld_variant LIKE syst-slset. "syslset.
DATA: lt_varvar LIKE rsvarvar OCCURS 0 WITH HEADER LINE.
DATA: lt_params LIKE rsparams OCCURS 0 WITH HEADER LINE.
DATA: lt_reports LIKE scma_wf_tasks OCCURS 0 WITH HEADER LINE.
* Batchinputdata of single transaction
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
SELECT-OPTIONS : s_rep FOR vari-report, "Report name(s)
s_var FOR vari-variant. "Variant Name(s)
* Once all the selection data is in the itab, sort it by report name
* Read from start to end
SORT lt_reports.
*Read
LOOP AT lt_reports.
* Clear work variables and update parameters for call
REFRESH lt_varvar.
REFRESH lt_params.
ld_program = lt_reports-report.
ld_variant = lt_reports-variant.
* Get all the variants for the report and store in LT_VARVAR
CALL FUNCTION 'RS_VARIANT_VARIABLES'
EXPORTING
program = ld_program
variant = ld_variant
TABLES
var = lt_varvar
EXCEPTIONS
variant_not_existent = 1.
*
CHECK sy-subrc IS INITIAL.
* Test to see if the ABAP compiles - Problems if this is omitted
generate report ld_program.
* Only process those without eror
IF NOT sy-subrc IS INITIAL.
CONTINUE.
ENDIF.
** Print the header for the report/variant (if parameters found)
* program is OK.
IF sy-subrc IS INITIAL.
format intensified on.
format color 1 on.
write:/ 'Report: ',ld_program, 'Variant: ', ld_variant.
format intensified off.
format reset.
HIDE: ld_program, ld_variant.
ENDIF.
ENDLOOP.
************************************************************
AT LINE-SELECTION.
CHECK NOT ld_program IS INITIAL.
PERFORM BDC_DYNPRO USING 'RS_CHANGE_VARIANT' '1000'.
PERFORM bdc_field USING 'P_REPO' ld_program.
PERFORM bdc_field USING 'P_VARI' ld_variant.
PERFORM bdc_field USING 'BDC_OKCODE' '=ONLI'.
CALL TRANSACTION 'VARCH' USING bdcdata MODE 'E' UPDATE 'S'.
REFRESH BDCDATA.
CLEAR: ld_program, ld_variant.
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
* IF FVAL <> NODATA.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
* ENDIF.
ENDFORM.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.